UNPKG

@test-org122/test-merchant-connector

Version:

An example dispute mediator for testing, which always resolve's in the sender's favor.

50 lines 1.91 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = __importDefault(require("express")); const fs_1 = __importDefault(require("fs")); const ethers_1 = require("ethers"); const cors_1 = __importDefault(require("cors")); var app = express_1.default(); app.use(cors_1.default()); //app.options('*', cors()); // This private key is from the ethers documentation, don't use it except for testing. const privateKey = "0x0123456789012345678901234567890123456789012345678901234567890123"; // Create a provider and connect it to the local blockchain const provider = new ethers_1.ethers.providers.JsonRpcProvider("http://localhost:8545"); // Create a wallet using that provider. Wallet combines a provider and a signer. const wallet = new ethers_1.ethers.Wallet(privateKey, provider); let connector = ""; let signature = "unknown"; let address = wallet.address; // Read the webpacked connector file. const filename = __dirname + "/connector/index.js"; fs_1.default.readFile(filename, 'utf8', (err, data) => { connector = data; // Sign the connector wallet.signMessage(connector).then((sig) => { console.log(`Signature: ${sig}`); signature = sig; }); }); app.get('/connector', (req, res) => { res.end(connector); }); app.get('/signature', (req, res) => { res.end(signature); }); app.get('/publicKey', (req, res) => { res.end(address); }); const server = app.listen(5010, () => { const addressInfo = server.address(); if (addressInfo != null) { var host = addressInfo.address; var port = addressInfo.port; console.log("Example Merchant listening at http://%s:%s", host, port); console.log(`filename: ${filename}`); } }); //# sourceMappingURL=index.js.map