-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdk.js
62 lines (56 loc) · 1.56 KB
/
sdk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
if (process.argv.includes("--version")) {
const pkg = require("./package.json");
console.log(pkg.name, pkg.version);
process.exit(0);
}
const crypto = require("node:crypto")
class CryptoHelper {
async sha256(msg) {
if (msg instanceof Uint8Array) {
return crypto
.createHash("sha256")
.update(msg)
.digest()
}
return crypto
.createHash("sha256")
.update(new Uint8Array(Buffer.from(msg)))
.digest()
}
async md5(data) {
const hash = crypto.createHash("md5")
if (data) {
return hash.update(data).digest()
}
return hash
}
async ripemd160(data) {
const hash = crypto.createHash("ripemd160")
if (data) {
return hash.update(data).digest()
}
return hash
}
}
globalThis.cryptoHelper = new CryptoHelper();
globalThis.walletBcf = require("@bfmeta/wallet-bcf");
globalThis.__signUtil = require("@bfmeta/sign-util");
async function returnToGo(req_id, handler) {
console.log("node env ready", process.versions.node);
try {
const result = await handler();
return `Result ${req_id} true ${JSON.stringify(result)}`;
} catch (e) {
return `Result ${req_id} false ${String(e)}`;
}
}
Object.assign(globalThis, {returnToGo});
console.log("node env ready", process.versions.node);
const repl = require("node:repl");
repl.start({
prompt: "",
writer: (output) => {
console.log(output);
},
});