@acurast/cli
Version:
A cli to interact with the Acurast Cloud.
51 lines • 2.22 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import Module from 'node:module';
import { subtle } from 'crypto';
const require = Module.createRequire(import.meta.url);
const Acurast = require('@acurast/dapp');
const client = new Acurast.AcurastClient([
'wss://websocket-proxy-1.prod.gke.acurast.com/',
'wss://websocket-proxy-2.prod.gke.acurast.com/',
]);
export const sendCode = (recipientPublicKey, code, callback) => __awaiter(void 0, void 0, void 0, function* () {
const keyPair = yield subtle.generateKey({
name: 'ECDSA',
namedCurve: 'P-256',
}, true, ['sign']);
const [privateKeyRaw, publicKeyRaw] = yield Promise.all([
subtle
.exportKey('jwk', keyPair.privateKey)
.then((jwk) => Buffer.from(jwk.d, 'base64')),
subtle
.exportKey('raw', keyPair.publicKey)
.then((arrayBuffer) => Buffer.from(arrayBuffer)),
]);
yield client.start({
secretKey: privateKeyRaw.toString('hex'),
publicKey: publicKeyRaw.toString('hex'),
});
client.onMessage((message) => {
const payload = Buffer.from(message.payload, 'hex').toString('utf8');
// console.log({
// sender: Buffer.from(message.sender).toString('hex'),
// recipient: Buffer.from(message.recipient).toString('hex'),
// payload,
// })
try {
callback(JSON.parse(payload));
}
catch (e) {
callback(payload);
}
});
client.send(recipientPublicKey, code);
});
//# sourceMappingURL=live-code.js.map