UNPKG

@acurast/cli

Version:

A cli to interact with the Acurast Cloud.

42 lines 1.5 kB
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 = async (recipientPublicKey, code, callback) => { const keyPair = await subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256', }, true, ['sign']); const [privateKeyRaw, publicKeyRaw] = await Promise.all([ subtle .exportKey('jwk', keyPair.privateKey) .then((jwk) => Buffer.from(jwk.d, 'base64')), subtle .exportKey('raw', keyPair.publicKey) .then((arrayBuffer) => Buffer.from(arrayBuffer)), ]); await 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