-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
80 lines (70 loc) · 2.24 KB
/
test.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//@ts-check
const { BCFWalletFactory } = require("@bfmeta/wallet-bcf");
const { BFMetaSignUtil } = require("@bfmeta/sign-util");
const { Buffer } = require("node:buffer");
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;
}
}
(async () => {
return;
const bfcwallet = BCFWalletFactory({
enable: true,
host: [{ ip: "34.84.178.63", port: 19503 }],
browserPath: "https://qapmapi.pmchainbox.com/browser",
});
console.log(bfcwallet);
console.log(`getAddressBalance`);
const r1 = await bfcwallet.getAddressBalance(
"cEAXDkaEJgWKMM61KYz2dYU1RfuxbB8Ma",
"XXVXQ",
"PMC"
);
console.log(r1, "bfchain");
})();
(async () => {
const signUtil = new BFMetaSignUtil("`+prefix+`", Buffer, new CryptoHelper());
// bfcwallet.sdk.api.transaction.broadcastCompleteTransaction();
// bfcwallet.sdk.api.transaction.createTransferAsset();
// bfcwallet.sdk.bfchainSignUtil.getAddressFromPublicKey
signUtil.createKeypair;
signUtil.createKeypairBySecretKeyString;
signUtil.getSecondPublicKeyStringFromSecretAndSecondSecret;
signUtil.detachedVeriy;
const msg = Buffer.from("utf8-1234");
const secretKey = Buffer.from(
"03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4caf0f4c00cf9240771975e42b6672c88a832f98f01825dda6e001e2aab0bc0cc",
"hex"
);
const publicKey = Buffer.from(
"caf0f4c00cf9240771975e42b6672c88a832f98f01825dda6e001e2aab0bc0cc",
"hex"
);
const signature = await signUtil.detachedSign(msg, secretKey);
console.log("detachedSign", signature.toString("hex"));
const verified = await signUtil.detachedVeriy(msg, signature, publicKey);
console.log("verified", verified);
// bfcwallet.sdk.bfchainSignUtil.createKeypairBySecretKeyString
})();