@walletpack/core
Version:
> TODO: description
521 lines (454 loc) • 17 kB
JavaScript
;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _Blockchains = require("../../models/Blockchains");
var PluginTypes = _interopRequireWildcard(require("../PluginTypes"));
var _Plugin2 = _interopRequireDefault(require("../Plugin"));
/***
* DO NOT INCLUDE
* This is just an interface for quickly raising
* new Scatter blockchain plugins
*/
var PluginInterface =
/*#__PURE__*/
function (_Plugin) {
(0, _inherits2["default"])(PluginInterface, _Plugin);
function PluginInterface() {
(0, _classCallCheck2["default"])(this, PluginInterface);
return (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(PluginInterface).call(this, 'blockchain_type', PluginTypes.BLOCKCHAIN_SUPPORT));
}
/***
* BIP is the path on a device such as a ledger (HD wallet).
* EXAMPLE: return `44'/0'/0'/0/`
*/
(0, _createClass2["default"])(PluginInterface, [{
key: "bip",
value: function bip() {}
/***
* If there is an internal cache, this method being called should clear it.
*/
}, {
key: "bustCache",
value: function bustCache() {}
/***
* Explorer is an object that points to a web-interface block explorer.
* {x} is used as a placeholder for an account/txid/block_id.
* EXAMPLE:
{
"name":"EXPLORER NAME",
"account":"https://explorer.com/account/{x}",
"transaction":"https://explorer.com/transaction/{x}",
"block":"https://explorer.com/block/{x}"
}
*/
}, {
key: "defaultExplorer",
value: function defaultExplorer() {}
/***
* Account formatter turns an `Account` model into a string which is used as the recipient of transactions.
* For instance in EOSIO blockchains the formatter would return `account.name`, but in Ethereum blockchains it would return
* `account.publicKey` which denotes the address instead of a name.
*/
}, {
key: "accountFormatter",
value: function accountFormatter(account) {}
/***
* Returnable account is a POJO that is returned to interacting applications.
* For instance, in EOSIO blockchains a name is required, however in Ethereum blockchains only a publicKey/address is required.
*/
}, {
key: "returnableAccount",
value: function returnableAccount(account) {}
/***
* This is a UI helper which defines what a placeholder value for a contract might be.
* For instance in Ethereum blockchains it might be `0x...`, while in EOSIO blockchains it might be `eosio.token`
*/
}, {
key: "contractPlaceholder",
value: function contractPlaceholder() {}
/***
* Check network simply checks the availability/connectivity of a `Network`.
* This should either resolve or timeout after 2-4 seconds.
*/
}, {
key: "checkNetwork",
value: function checkNetwork(network) {}
/***
* An endorsed network is simply a "default" network hardcoded into the plugin, providing an absolute fallback
* for a node connection.
* THIS MUST RETURN A NETWORK CLASS
* EXAMPLE:
return new Network('EOS Mainnet', 'https', 'nodes.get-scatter.com', 443, Blockchains.EOSIO, MAINNET_CHAIN_ID)
*/
}, {
key: "getEndorsedNetwork",
value: function getEndorsedNetwork() {}
/***
* Checks if a given network is the endorsed network (or a network matching the chainID)
* EXAMPLE:
return network.blockchain === Blockchains.EOSIO && network.chainId === MAINNET_CHAIN_ID;
*/
}, {
key: "isEndorsedNetwork",
value: function isEndorsedNetwork(network) {}
/***
* Fetches the chainID from the network (live) if available.
*/
}, {
key: "getChainId",
value: function () {
var _getChainId = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee(network) {
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
case "end":
return _context.stop();
}
}
}, _callee);
}));
function getChainId(_x) {
return _getChainId.apply(this, arguments);
}
return getChainId;
}()
/***
* If specialized actions are required by the blockchain (like key management) this
* should return true, otherwise false.
* In the case of `true`, the plugin must also include an `accountActions` method
*/
}, {
key: "hasAccountActions",
value: function hasAccountActions() {} // OPTIONAL, this is only required if `hasAccountActions` is `true`.
// accountActions(account, callback){
// return [
// new AccountAction("unlink_account", () => callback(account)),
// new AccountAction("change_permissions", () => callback(account), true),
// ];
// }
/***
* This might need to be re-designed to be dynamic, however this designates a
* blockchain as using resources like CPU/NET/RAM on EOSIO blockchains.
* If this is true, then `getResourcesFor(account)`, `needsResources(account)` and `addResources(account)` must also be included.
* For examples check the EOSIO plugin.
*/
}, {
key: "usesResources",
value: function usesResources() {
return false;
}
/***
* Accounts are sometimes required to be created or imported before being available (such is the case in EOSIO blockchains).
* If this is set to false, a dummy account will always be created using the publicKey/address. If not, then an account creation
* process will need to be created on the front-end which will require UI work.
*/
}, {
key: "accountsAreImported",
value: function accountsAreImported() {
return false;
}
/***
* Should check whether a string account_name/address is a valid recipient.
*/
}, {
key: "isValidRecipient",
value: function isValidRecipient(name) {}
/***
* Converts a private key to a public key
*/
}, {
key: "privateToPublic",
value: function privateToPublic(privateKey) {}
/***
* Checks whether a private key is valid
*/
}, {
key: "validPrivateKey",
value: function validPrivateKey(privateKey) {}
/***
* Checks whether a public key is valid
*/
}, {
key: "validPublicKey",
value: function validPublicKey(publicKey) {}
/***
* Generates a random private key
* NOTE: This isn't used in Scatter, as we use buffer keys generated elsewhere.
*/
}, {
key: "randomPrivateKey",
value: function randomPrivateKey() {}
/***
* Converts a byte buffer into a hex private key.
*/
}, {
key: "bufferToHexPrivate",
value: function bufferToHexPrivate(buffer) {}
/***
* Converts a hex private key into a byte buffer.
*/
}, {
key: "hexPrivateToBuffer",
value: function hexPrivateToBuffer(privateKey) {}
/***
* Takes a transaction payload and returns a flat array of participants.
* EXAMPLES:
* EOSIO: ['testaccount@active']
* ETHEREUM: ['0x....']
*/
}, {
key: "actionParticipants",
value: function actionParticipants(payload) {}
/***
* Untouchable tokens are things like staked tokens on the system level.
* If a blockchain has untouchable (un-usable/un-transferable) tokens, then a `async untouchableBalance(account)` method
* must also be provided which returns an array of `Token` class.
*/
}, {
key: "hasUntouchableTokens",
value: function hasUntouchableTokens() {
return false;
}
/***
* Gets a single token's balance.
* Returns a Token class where `token.amount` is the balance.
*/
}, {
key: "balanceFor",
value: function () {
var _balanceFor = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee2(account, token) {
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
function balanceFor(_x2, _x3) {
return _balanceFor.apply(this, arguments);
}
return balanceFor;
}()
/***
* Gets an array of token's values.
* The `tokens` param might also be omitted which would mean to grab "all available tokens for an account".
* Returns an array of Token class.
*/
}, {
key: "balancesFor",
value: function () {
var _balancesFor = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee3(account) {
var tokens,
_args3 = arguments;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
tokens = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : null;
case 1:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
function balancesFor(_x4) {
return _balancesFor.apply(this, arguments);
}
return balancesFor;
}()
/***
* The default decimal count for tokens on this blockchain.
* Returns an integer.
*/
}, {
key: "defaultDecimals",
value: function defaultDecimals() {}
/***
* The default token for this blockchain.
* Returns a Token class.
*/
}, {
key: "defaultToken",
value: function defaultToken() {}
/***
* This is usually used internally inside of your walletpack plugin.
* Simply takes a payload and converts it into a request that signing popups understand.
* Check one of the existing plugins for the structures.
* EXAMPLE:
payload.messages = [...];
payload.identityKey = StoreService.get().state.scatter.keychain.identities[0].publicKey;
payload.participants = [account];
payload.network = account.network();
payload.origin = 'Scatter';
const request = {
payload,
origin:payload.origin,
blockchain:'YOUR BLOCKCHAIN',
requiredFields:{},
type:Actions.SIGN,
id:1,
};
*/
}, {
key: "signerWithPopup",
value: function () {
var _signerWithPopup = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee4(payload, account, rejector) {
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
case "end":
return _context4.stop();
}
}
}, _callee4);
}));
function signerWithPopup(_x5, _x6, _x7) {
return _signerWithPopup.apply(this, arguments);
}
return signerWithPopup;
}()
/***
* Creates a token transfer. Should use the signerWithPopup above to
* create a popup which the users has to sign.
* This might also be requested to be bypassed sometimes with the `prompForSignature = false` flag param.
*/
}, {
key: "transfer",
value: function () {
var _transfer = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee5(_ref) {
var account, to, amount, contract, symbol, memo, _ref$promptForSignatu, promptForSignature;
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
account = _ref.account, to = _ref.to, amount = _ref.amount, contract = _ref.contract, symbol = _ref.symbol, memo = _ref.memo, _ref$promptForSignatu = _ref.promptForSignature, promptForSignature = _ref$promptForSignatu === void 0 ? true : _ref$promptForSignatu;
case 1:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
function transfer(_x8) {
return _transfer.apply(this, arguments);
}
return transfer;
}()
/***
* Does the actual signing of a transaction.
* The `payload` will vary based on blockchain as it comes directly from their own libraries.
* The goal of this method is to turn a payload into a signed transaction though, so if that works in tests then
* it will work perfectly elsewhere.
* Notes:
* `arbitrary` and `isHash`: Sometimes blockchains change signing types based on whether a signature is signing a string (arbitrary) or a hash.
*/
}, {
key: "signer",
value: function () {
var _signer = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee6(payload, publicKey) {
var arbitrary,
isHash,
privateKey,
_args6 = arguments;
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
arbitrary = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : false;
isHash = _args6.length > 3 && _args6[3] !== undefined ? _args6[3] : false;
privateKey = _args6.length > 4 && _args6[4] !== undefined ? _args6[4] : null;
case 3:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
function signer(_x9, _x10) {
return _signer.apply(this, arguments);
}
return signer;
}()
}, {
key: "requestParser",
/***
* The goal of this method is to parse a `payload` into something which UI's understand.
* Payload will differ based on blockchain, as it depends on the blockchain's actual javascript library.
* The `abi` parameter is needed for blockchains which don't have on-chain ABI stores (which is bad).
*
* The results of this method should be an array structured as follows:
[
// Many actions can be in the result as some blockchain support multiple actions within a transaction (batch).
{
// This is a key-value pair of the details of the transaction.
// These details will be displayed for the user in the signature prompt.
data:{
hello:'world',
value:1,
object:{...}
}
// The contract name, or in the case of a system token transfer then the account_name/address being sent to
code,
// Either the method name for a smart contract, or `transfer` for a system token transfer.
type,
// The authorizor of this transaction (account_name/address STRING)
authorization
}
]
*/
value: function () {
var _requestParser = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee7(payload, network) {
var abi,
_args7 = arguments;
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
abi = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : null;
case 1:
case "end":
return _context7.stop();
}
}
}, _callee7);
}));
function requestParser(_x11, _x12) {
return _requestParser.apply(this, arguments);
}
return requestParser;
}()
}]);
return PluginInterface;
}(_Plugin2["default"]);
exports["default"] = PluginInterface;