-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign-and-request.js.js
50 lines (40 loc) · 1.38 KB
/
sign-and-request.js.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
const { Keypair } = require('@solana/web3.js');
const { TextEncoder } = require('util');
const nacl = require('tweetnacl');
// The provided secret key array
const secretKeyArray = [
];
const secretKey = Uint8Array.from(secretKeyArray);
const keypair = Keypair.fromSecretKey(secretKey);
// Message to sign
const message = 'Hello Nosana Node!';
const encodedMessage = new TextEncoder().encode(message);
// Use tweetnacl to sign the message
const signature = nacl.sign.detached(encodedMessage, keypair.secretKey);
const signatureBase64 = Buffer.from(signature).toString('base64');
const publicKeyString = keypair.publicKey.toBase58();
// Node API endpoint
const nodeUrl = 'https://3vwMHHicGk9enrHst7cJhbucNWSMyMDuB8G9HX1DQk7A.node.k8s.dev.nos.ci/service/stop/testjobid123';
// Headers
const headers = {
Authorization: `${publicKeyString}:${signatureBase64}`
};
(async () => {
try {
// Using native fetch in Node.js 18+
const response = await fetch(nodeUrl, {
method: 'POST',
headers
});
const text = await response.text();
console.log('Response status:', response.status);
console.log('Response body:', text);
if (!response.ok) {
console.error('Error stopping job:', response.status, text);
} else {
console.log('Job stopped successfully (or no job found, but auth worked).');
}
} catch (error) {
console.error('Error:', error);
}
})();