-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
70 lines (62 loc) · 1.69 KB
/
index.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
const bitcoin = require("bitcoinjs-lib");
const bitcoinMessage = require("bitcoinjs-message");
const CoinKey = require("coinkey");
const coininfo = require("coininfo"); //coininfo gives us meta data about a bunch of crypto currencies, including Ravencoin
const frmt = coininfo.ravencoin.main.toBitcoinJS();
const RAVENCOIN_NETWORK = {
messagePrefix: "\x16Raven Signed Message:\n",
bip32: {
public: frmt.bip32.public,
private: frmt.bip32.private,
},
pubKeyHash: frmt.pubKeyHash,
scriptHash: frmt.scriptHash,
wif: frmt.wif,
};
const message = "This is an example of a signed message.";
const privateKeyWIF = "KwTnXnJ4kbAf29wYEmXkB3xkCm8byYxg3hkPt8yhd37ofjwj7h8F";
//Import private key as WIF and set coinkey to use MAIN-net for Ravencoin
const coinkey = CoinKey.fromWif(privateKeyWIF);
coinkey.versions = coininfo("RVN").versions;
const { address } = bitcoin.payments.p2pkh({
pubkey: coinkey.publicKey,
network: RAVENCOIN_NETWORK,
});
const privateKey = coinkey.privateKey;
/*
export function sign(
message: string | Buffer,
privateKey: Buffer | Signer,
compressed?: boolean,
messagePrefix?: string,
sigOptions?: SignatureOptions
): Buffer;
*/
var signature = bitcoinMessage.sign(
message,
privateKey,
coinkey.compressed,
RAVENCOIN_NETWORK.messagePrefix
);
const table = {
address,
message,
signature: signature.toString("base64"),
};
console.table(table);
/*
export function verify(
message: string | Buffer,
address: string,
signature: string | Buffer,
messagePrefix?: string,
checkSegwitAlways?: boolean
): boolean;
*/
const result = bitcoinMessage.verify(
message,
address,
signature,
RAVENCOIN_NETWORK.messagePrefix
);
console.log("Result", result);