UNPKG

@bsv/p2p

Version:

A client for P2P messaging and payments

89 lines 3.84 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const sdk_1 = require("@bsv/sdk"); const MessageBoxClient_js_1 = require("./MessageBoxClient.js"); const crypto = __importStar(require("crypto")); global.self = { crypto }; (async () => { const messageBoxClient = new MessageBoxClient_js_1.MessageBoxClient({ walletClient: new sdk_1.WalletClient('auto', 'local'), // NOTE Fix bug host: 'https://staging-messagebox.babbage.systems', enableLogging: true }); // await messageBoxClient.init() const result = await messageBoxClient.listMessages({ messageBox: 'L3_inbox' }); console.log(result); // await messageBoxClient.acknowledgeMessage({ messageIds: [result[0].messageId] }) // const result = await messageBoxClient.sendMessage({ // recipient: '0350fa50d7c23f63d949c9532f41a7ea0c01112ffb1404cfb8a9f732b11a54a1ce', // messageBox: 'test_inbox', // body: { data: 'test' } // }) // console.log('Message sent successfully:', result) // const kv = new LocalKVStore(new WalletClient('auto', 'local')) // await kv.set('testKey', 'New value') // const value = await kv.get('testKey') // console.log('Value from local storage:', value) // const payloadNum = 1_234_567_890 // any number you like // const payloadBuf = Utils.toArray('HELLO WORLD', 'utf8') // 4-byte LE // const script = new Script() // .writeOpCode(OP.OP_FALSE) // 0x00 // .writeOpCode(OP.OP_RETURN) // 0x6a // .writeBin(payloadBuf) // push your data // // --------------------------------------------------------------------------- // // 2. Fund, sign and broadcast with WalletClient // // ('auto' = pick current network, 'local' = talk to kernel at localhost:3301) // // --------------------------------------------------------------------------- // const wc = new WalletClient('auto', 'local') // const { txid } = await wc.createAction({ // description: 'Data test', // outputs: [ // { // lockingScript: script.toHex(), // <-- correct field name // satoshis: 0, // outputDescription: 'test' // } // ], // options: { // acceptDelayedBroadcast: false, // randomizeOutputs: false // } // }) // console.log('Transaction ID:', txid) })(); //# sourceMappingURL=sendMessageTest.js.map