revos-sdk-js-mainnet
Version:
revos client and wallet SDK
56 lines (39 loc) • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var address = _interopRequireWildcard(require("./address"));
var common = _interopRequireWildcard(require("../common"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
class Account {
constructor(seed, options = {}) {
_defineProperty(this, "key", void 0);
_defineProperty(this, "signatureRedeem", void 0);
_defineProperty(this, "programHash", void 0);
_defineProperty(this, "address", void 0);
_defineProperty(this, "contract", void 0);
this.key = new common.Key(seed, {
worker: options.worker
});
this.signatureRedeem = address.publicKeyToSignatureRedeem(this.key.publicKey);
this.programHash = address.hexStringToProgramHash(this.signatureRedeem);
this.address = address.programHashStringToAddress(this.programHash);
this.contract = genAccountContractString(this.signatureRedeem, this.programHash);
}
getPublicKey() {
return this.key.publicKey;
}
getSeed() {
return this.key.seed;
}
}
exports.default = Account;
function genAccountContractString(signatureRedeem, programHash) {
let contract = address.prefixByteCountToHexString(signatureRedeem);
contract += address.prefixByteCountToHexString('00');
contract += programHash;
return contract;
}