dotbit-sdk-allin
Version:
A complete .bit SDK and utilities in TypeScript
40 lines • 1.87 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 { signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util';
import { ethers } from 'ethers';
import { remove0x } from '../tools/common';
import { BitSigner } from './BitSigner';
export class EthersSigner extends BitSigner {
constructor(signer) {
super();
this.signer = signer;
}
signTypedData(data) {
return __awaiter(this, void 0, void 0, function* () {
return signTypedData({
privateKey: Buffer.from(remove0x(this.signer.privateKey), 'hex'),
data,
version: SignTypedDataVersion.V4,
});
});
}
sendTransaction(sendTransactionParam) {
return __awaiter(this, void 0, void 0, function* () {
const _data = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(sendTransactionParam.data));
const { hash } = yield this.signer.sendTransaction({
to: sendTransactionParam.to,
value: ethers.BigNumber.from(sendTransactionParam.value),
data: _data
});
return hash;
});
}
}
//# sourceMappingURL=EthersSigner.js.map