aion-gql-webcomponents
Version:
AION Webcomponents using AION GraphQL
29 lines (28 loc) • 953 B
JavaScript
import { TransactionUtil } from "../util/TransactionUtil";
export default class PrivateKeyWalletProvider {
constructor(privateKey) {
this.privateKey = privateKey;
}
async unlock(progressCallback) {
try {
let [address, publicKey] = TransactionUtil.getAddress(this.privateKey);
this.address = address;
this.publicKey = publicKey;
if (progressCallback)
progressCallback(100);
return [address, publicKey];
}
catch (e) {
console.log(e);
throw e;
}
}
async sign(transaction) {
let mainThis = this;
if (!mainThis.privateKey) {
throw new Error("Can not sign a transaction with null privatekey");
}
let encodedSignedTxn = TransactionUtil.signTransaction(transaction, mainThis.privateKey);
return encodedSignedTxn;
}
}