@test-org122/test-merchant-connector
Version:
An example dispute mediator for testing, which always resolve's in the sender's favor.
52 lines • 2.96 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const rxjs_1 = require("rxjs");
const utils_1 = require("ethers/lib/utils");
const vector_utils_1 = require("@connext/vector-utils");
class TestMerchantConnector {
constructor() {
this.onSendFundsRequested = new rxjs_1.Subject();
this.onAuthorizeFundsRequested = new rxjs_1.Subject();
this.onDisplayRequested = new rxjs_1.Subject();
}
resolveChallenge(paymentId) {
return __awaiter(this, void 0, void 0, function* () {
// What the mediator needs to sign:
// https://github.com/connext/transfers/blob/20f44307164cb245c075cf3723b09d8ff75901d4/tests/insurance/insurance.spec.ts#L399
// Case: mediator decides to resolve payment in full (ie, the entire insurance payment)
const resolutionAmount = "1";
// 1) Construct the ABI snippet for the data we want to sign
const resolverDataEncoding = ["tuple(uint256 amount, bytes32 UUID)"];
// 2) Prepare the (un-encoded) data
const resolverData = { amount: resolutionAmount, UUID: paymentId };
// 3) Encode the data
const encodedData = utils_1.defaultAbiCoder.encode(resolverDataEncoding, [resolverData]);
// 4) Hash the data so that it's a set length
const hashedData = utils_1.keccak256(encodedData);
// 5) Sign the hash of the data so that people know we sent it
// Note, it is assumed this is being done on the Merchant's server, and this private key is protected.
const privateKey = "0x0123456789012345678901234567890123456789012345678901234567890123";
let mediator = new vector_utils_1.ChannelSigner(privateKey);
const mediatorSignature = yield mediator.signUtilityMessage(hashedData);
// 6) Return both the signature of the hash of the data & the data itself
return Promise.resolve({
mediatorSignature,
amount: resolutionAmount,
});
});
}
getPublicKey() {
return Promise.resolve("0x14791697260E4c9A71f18484C9f997B308e59325");
}
}
window.connector = new TestMerchantConnector();
//# sourceMappingURL=index.js.map