PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/@celo/contractkit/lib/wrappers
Просмотр файла: Accounts.js
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountsWrapper = void 0;
var signatureUtils_1 = require("@celo/base/lib/signatureUtils");
var connect_1 = require("@celo/connect");
var signatureUtils_2 = require("@celo/utils/lib/signatureUtils");
var solidity_1 = require("@celo/utils/lib/solidity");
var typed_data_constructors_1 = require("@celo/utils/lib/typed-data-constructors");
var versions_1 = require("../versions");
var BaseWrapper_1 = require("../wrappers/BaseWrapper");
var BaseWrapper_2 = require("./BaseWrapper");
/**
* Contract for handling deposits needed for voting.
*/
var AccountsWrapper = /** @class */ (function (_super) {
__extends(AccountsWrapper, _super);
function AccountsWrapper() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.RELEASE_4_VERSION = (0, versions_1.newContractVersion)(1, 1, 2, 0);
/**
* Creates an account.
*/
_this.createAccount = (0, BaseWrapper_1.proxySend)(_this.connection, _this.contract.methods.createAccount);
/**
* Returns the attestation signer for the specified account.
* @param account The address of the account.
* @return The address with which the account can vote.
*/
_this.getAttestationSigner = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.getAttestationSigner);
/**
* Returns if the account has authorized an attestation signer
* @param account The address of the account.
* @return If the account has authorized an attestation signer
*/
_this.hasAuthorizedAttestationSigner = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.hasAuthorizedAttestationSigner);
/**
* Returns the vote signer for the specified account.
* @param account The address of the account.
* @return The address with which the account can vote.
*/
_this.getVoteSigner = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.getVoteSigner);
/**
* Returns the validator signer for the specified account.
* @param account The address of the account.
* @return The address with which the account can register a validator or group.
*/
_this.getValidatorSigner = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.getValidatorSigner);
/**
* Returns the account address given the signer for voting
* @param signer Address that is authorized to sign the tx as voter
* @return The Account address
*/
_this.voteSignerToAccount = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.voteSignerToAccount);
/**
* Returns the account address given the signer for validating
* @param signer Address that is authorized to sign the tx as validator
* @return The Account address
*/
_this.validatorSignerToAccount = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.validatorSignerToAccount);
/**
* Returns the account associated with `signer`.
* @param signer The address of the account or previously authorized signer.
* @dev Fails if the `signer` is not an account or previously authorized signer.
* @return The associated account.
*/
_this.signerToAccount = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.signerToAccount);
/**
* Check if an account already exists.
* @param account The address of the account
* @return Returns `true` if account exists. Returns `false` otherwise.
*/
_this.isAccount = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.isAccount);
/**
* Check if an address is a signer address
* @param address The address of the account
* @return Returns `true` if account exists. Returns `false` otherwise.
*/
_this.isSigner = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.isAuthorizedSigner);
/**
* Returns the set data encryption key for the account
* @param account Account
*/
_this.getDataEncryptionKey = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.getDataEncryptionKey, undefined, function (res) {
return (0, BaseWrapper_1.solidityBytesToString)(res);
});
/**
* Returns the set wallet address for the account
* @param account Account
*/
_this.getWalletAddress = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.getWalletAddress);
/**
* Returns the metadataURL for the account
* @param account Account
*/
_this.getMetadataURL = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.getMetadataURL);
/**
* Sets the data encryption of the account
* @param encryptionKey The key to set
*/
_this.setAccountDataEncryptionKey = (0, BaseWrapper_1.proxySend)(_this.connection, _this.contract.methods.setAccountDataEncryptionKey);
/**
* Sets the name for the account
* @param name The name to set
*/
_this.setName = (0, BaseWrapper_1.proxySend)(_this.connection, _this.contract.methods.setName);
/**
* Sets the metadataURL for the account
* @param url The url to set
*/
_this.setMetadataURL = (0, BaseWrapper_1.proxySend)(_this.connection, _this.contract.methods.setMetadataURL);
/**
* Set a validator's payment delegation settings.
* @param beneficiary The address that should receive a portion of validator
* payments.
* @param fraction The fraction of the validator's payment that should be
* diverted to `beneficiary` every epoch, given as FixidityLib value. Must not
* be greater than 1.
* @dev Use `deletePaymentDelegation` to unset the payment delegation.
*/
_this.setPaymentDelegation = (0, BaseWrapper_1.proxySend)(_this.connection, _this.contract.methods.setPaymentDelegation);
/**
* Remove a validator's payment delegation by setting benficiary and
* fraction to 0.
*/
_this.deletePaymentDelegation = (0, BaseWrapper_1.proxySend)(_this.connection, _this.contract.methods.deletePaymentDelegation);
/**
* Get a validator's payment delegation settings.
* @param account Account of the validator.
* @return Beneficiary address and fraction of payment delegated.
*/
_this.getPaymentDelegation = (0, BaseWrapper_1.proxyCall)(_this.contract.methods.getPaymentDelegation);
return _this;
}
AccountsWrapper.prototype.getCurrentSigners = function (address) {
return Promise.all([
this.getVoteSigner(address),
this.getValidatorSigner(address),
this.getAttestationSigner(address),
]);
};
AccountsWrapper.prototype.getAccountSummary = function (account) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all([
this.getName(account),
this.getVoteSigner(account),
this.getValidatorSigner(account),
this.getAttestationSigner(account),
this.getMetadataURL(account),
this.getWalletAddress(account),
this.getDataEncryptionKey(account),
])];
case 1:
ret = _a.sent();
return [2 /*return*/, {
address: account,
name: ret[0],
authorizedSigners: {
vote: ret[1],
validator: ret[2],
attestation: ret[3],
},
metadataURL: ret[4],
wallet: ret[5],
dataEncryptionKey: ret[6],
}];
}
});
});
};
/**
* Authorize an attestation signing key on behalf of this account to another address.
* @param signer The address of the signing key to authorize.
* @param proofOfSigningKeyPossession The account address signed by the signer address.
* @return A CeloTransactionObject
*/
AccountsWrapper.prototype.authorizeAttestationSigner = function (signer, proofOfSigningKeyPossession) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.authorizeAttestationSigner(signer, proofOfSigningKeyPossession.v, proofOfSigningKeyPossession.r, proofOfSigningKeyPossession.s))];
});
});
};
/**
* Authorizes an address to sign votes on behalf of the account.
* @param signer The address of the vote signing key to authorize.
* @param proofOfSigningKeyPossession The account address signed by the signer address.
* @return A CeloTransactionObject
*/
AccountsWrapper.prototype.authorizeVoteSigner = function (signer, proofOfSigningKeyPossession) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.authorizeVoteSigner(signer, proofOfSigningKeyPossession.v, proofOfSigningKeyPossession.r, proofOfSigningKeyPossession.s))];
});
});
};
/**
* Authorizes an address to sign consensus messages on behalf of the account.
* @param signer The address of the signing key to authorize.
* @param proofOfSigningKeyPossession The account address signed by the signer address.
* @return A CeloTransactionObject
*/
AccountsWrapper.prototype.authorizeValidatorSigner = function (signer, proofOfSigningKeyPossession, validatorsWrapper) {
return __awaiter(this, void 0, void 0, function () {
var account, _a, message, prefixedMsg, pubKey;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this.connection.defaultAccount;
if (_a) return [3 /*break*/, 2];
return [4 /*yield*/, this.connection.getAccounts()];
case 1:
_a = (_b.sent())[0];
_b.label = 2;
case 2:
account = _a;
return [4 /*yield*/, validatorsWrapper.isValidator(account)];
case 3:
if (_b.sent()) {
message = this.connection.web3.utils.soliditySha3({
type: 'address',
value: account,
});
prefixedMsg = (0, signatureUtils_2.hashMessageWithPrefix)(message);
pubKey = (0, signatureUtils_2.signedMessageToPublicKey)(prefixedMsg, proofOfSigningKeyPossession.v, proofOfSigningKeyPossession.r, proofOfSigningKeyPossession.s);
return [2 /*return*/, (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.authorizeValidatorSignerWithPublicKey(signer, proofOfSigningKeyPossession.v, proofOfSigningKeyPossession.r, proofOfSigningKeyPossession.s, (0, BaseWrapper_1.stringToSolidityBytes)(pubKey)))];
}
else {
return [2 /*return*/, (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.authorizeValidatorSigner(signer, proofOfSigningKeyPossession.v, proofOfSigningKeyPossession.r, proofOfSigningKeyPossession.s))];
}
return [2 /*return*/];
}
});
});
};
/**
* Authorizes an address to sign consensus messages on behalf of the account. Also switch BLS key at the same time.
* @param signer The address of the signing key to authorize.
* @param proofOfSigningKeyPossession The account address signed by the signer address.
* @param blsPublicKey The BLS public key that the validator is using for consensus, should pass proof
* of possession. 48 bytes.
* @param blsPop The BLS public key proof-of-possession, which consists of a signature on the
* account address. 96 bytes.
* @return A CeloTransactionObject
*/
AccountsWrapper.prototype.authorizeValidatorSignerAndBls = function (signer, proofOfSigningKeyPossession, blsPublicKey, blsPop) {
return __awaiter(this, void 0, void 0, function () {
var account, _a, message, prefixedMsg, pubKey;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this.connection.defaultAccount;
if (_a) return [3 /*break*/, 2];
return [4 /*yield*/, this.connection.getAccounts()];
case 1:
_a = (_b.sent())[0];
_b.label = 2;
case 2:
account = _a;
message = this.connection.web3.utils.soliditySha3({
type: 'address',
value: account,
});
prefixedMsg = (0, signatureUtils_2.hashMessageWithPrefix)(message);
pubKey = (0, signatureUtils_2.signedMessageToPublicKey)(prefixedMsg, proofOfSigningKeyPossession.v, proofOfSigningKeyPossession.r, proofOfSigningKeyPossession.s);
return [2 /*return*/, (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.authorizeValidatorSignerWithKeys(signer, proofOfSigningKeyPossession.v, proofOfSigningKeyPossession.r, proofOfSigningKeyPossession.s, (0, BaseWrapper_1.stringToSolidityBytes)(pubKey), (0, BaseWrapper_1.stringToSolidityBytes)(blsPublicKey), (0, BaseWrapper_1.stringToSolidityBytes)(blsPop)))];
}
});
});
};
AccountsWrapper.prototype.authorizeSigner = function (signer, role) {
return __awaiter(this, void 0, void 0, function () {
var _a, accounts, chainId, account, hashedRole, typedData, sig;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, this.onlyVersionOrGreater(this.RELEASE_4_VERSION)];
case 1:
_b.sent();
return [4 /*yield*/, Promise.all([
this.connection.getAccounts(),
this.connection.chainId(),
// This IS the accounts contract wrapper no need to get it
])];
case 2:
_a = _b.sent(), accounts = _a[0], chainId = _a[1];
account = this.connection.defaultAccount || accounts[0];
hashedRole = this.keccak256(role);
typedData = (0, typed_data_constructors_1.authorizeSigner)({
account: account,
signer: signer,
chainId: chainId,
role: hashedRole,
accountsContractAddress: this.address,
});
return [4 /*yield*/, this.connection.signTypedData(signer, typedData)];
case 3:
sig = _b.sent();
return [2 /*return*/, (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.authorizeSignerWithSignature(signer, hashedRole, sig.v, sig.r, sig.s))];
}
});
});
};
AccountsWrapper.prototype.startSignerAuthorization = function (signer, role) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.onlyVersionOrGreater(this.RELEASE_4_VERSION)];
case 1:
_a.sent();
return [2 /*return*/, (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.authorizeSigner(signer, this.keccak256(role)))];
}
});
});
};
AccountsWrapper.prototype.completeSignerAuthorization = function (account, role) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.onlyVersionOrGreater(this.RELEASE_4_VERSION)];
case 1:
_a.sent();
return [2 /*return*/, (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.completeSignerAuthorization(account, this.keccak256(role)))];
}
});
});
};
/**
* Removes the currently authorized attestation signer for the account
* @returns A CeloTransactionObject
*/
AccountsWrapper.prototype.removeAttestationSigner = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.removeAttestationSigner())];
});
});
};
AccountsWrapper.prototype.generateProofOfKeyPossession = function (account, signer) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.getParsedSignatureOfAddress(account, signer, (0, signatureUtils_1.NativeSigner)(this.connection.web3.eth.sign, signer))];
});
});
};
AccountsWrapper.prototype.generateProofOfKeyPossessionLocally = function (account, signer, privateKey) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.getParsedSignatureOfAddress(account, signer, (0, signatureUtils_2.LocalSigner)(privateKey))];
});
});
};
/**
* Returns the set name for the account
* @param account Account
* @param blockNumber Height of result, defaults to tip.
*/
AccountsWrapper.prototype.getName = function (account, blockNumber) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
// @ts-ignore: Expected 0-1 arguments, but got 2
return [2 /*return*/, this.contract.methods.getName(account).call({}, blockNumber)];
});
});
};
/**
* Convenience Setter for the dataEncryptionKey and wallet address for an account
* @param name A string to set as the name of the account
* @param dataEncryptionKey secp256k1 public key for data encryption. Preferably compressed.
* @param walletAddress The wallet address to set for the account
* @param proofOfPossession Signature from the wallet address key over the sender's address
*/
AccountsWrapper.prototype.setAccount = function (name, dataEncryptionKey, walletAddress, proofOfPossession) {
if (proofOfPossession === void 0) { proofOfPossession = null; }
if (proofOfPossession) {
return (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.setAccount(name,
// @ts-ignore
dataEncryptionKey, walletAddress, proofOfPossession.v, proofOfPossession.r, proofOfPossession.s));
}
else {
return (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.setAccount(name,
// @ts-ignore
dataEncryptionKey, walletAddress, '0x0', '0x0', '0x0'));
}
};
/**
* Sets the wallet address for the account
* @param address The address to set
*/
AccountsWrapper.prototype.setWalletAddress = function (walletAddress, proofOfPossession) {
if (proofOfPossession === void 0) { proofOfPossession = null; }
if (proofOfPossession) {
return (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.setWalletAddress(walletAddress, proofOfPossession.v, proofOfPossession.r, proofOfPossession.s));
}
else {
return (0, connect_1.toTransactionObject)(this.connection, this.contract.methods.setWalletAddress(walletAddress, '0x0', '0x0', '0x0'));
}
};
AccountsWrapper.prototype.parseSignatureOfAddress = function (address, signer, signature) {
var hash = (0, solidity_1.soliditySha3)({ type: 'address', value: address });
return (0, signatureUtils_2.parseSignature)(hash, signature, signer);
};
AccountsWrapper.prototype.getParsedSignatureOfAddress = function (address, signer, signerFn) {
return __awaiter(this, void 0, void 0, function () {
var hash, signature;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
hash = (0, solidity_1.soliditySha3)({ type: 'address', value: address });
return [4 /*yield*/, signerFn.sign(hash)];
case 1:
signature = _a.sent();
return [2 /*return*/, (0, signatureUtils_2.parseSignature)(hash, signature, signer)];
}
});
});
};
AccountsWrapper.prototype.keccak256 = function (value) {
return this.connection.keccak256(value);
};
return AccountsWrapper;
}(BaseWrapper_2.BaseWrapper));
exports.AccountsWrapper = AccountsWrapper;
//# sourceMappingURL=Accounts.js.mapВыполнить команду
Для локальной разработки. Не используйте в интернете!