-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
33 lines (28 loc) · 849 Bytes
/
index.ts
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
// Typescript example
import * as tls from 'tls';
import { Socket } from '../src/socket';
Socket.tlsSocket('electrum.villocq.com', 50002, {
rejectUnauthorized: false,
checkServerIdentity: () => undefined, // Self signed cert
}).then(async (socket: tls.TLSSocket) => {
// Set options
socket.setEncoding('utf8');
socket.setKeepAlive(true, 0);
socket.setNoDelay(true);
// Get peer certificate
const cert = Socket.getPeerCertificate(socket).raw;
// Convert DER cert to PEM cert if needed
console.log(Socket.derCertToPemCert(cert));
// Make requests
const balance = await Socket.request(
socket,
1,
'blockchain.address.get_balance',
['1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'],
);
console.log(JSON.parse(balance as string));
})
.catch((error) => {
console.log(error.error);
Socket.close(error.socket);
});