@metamask/keyring-api
Version:
MetaMask Keyring API
195 lines • 7.37 kB
JavaScript
"use strict";
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
// FIXME: This rule seems to be triggering a false positive on the `KeyringEvents`.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountAssetListUpdatedEventStruct = exports.AccountTransactionsUpdatedEventStruct = exports.AccountBalancesUpdatedEventStruct = exports.RequestRejectedEventStruct = exports.RequestApprovedEventStruct = exports.AccountDeletedEventStruct = exports.AccountUpdatedEventStruct = exports.AccountCreatedEventStruct = exports.KeyringEvent = void 0;
const keyring_utils_1 = require("@metamask/keyring-utils");
const superstruct_1 = require("@metamask/superstruct");
const utils_1 = require("@metamask/utils");
const api_1 = require("./api/index.cjs");
/**
* Supported keyring events.
*/
var KeyringEvent;
(function (KeyringEvent) {
// Account events
KeyringEvent["AccountCreated"] = "notify:accountCreated";
KeyringEvent["AccountUpdated"] = "notify:accountUpdated";
KeyringEvent["AccountDeleted"] = "notify:accountDeleted";
// Request events
KeyringEvent["RequestApproved"] = "notify:requestApproved";
KeyringEvent["RequestRejected"] = "notify:requestRejected";
// Assets related events
KeyringEvent["AccountBalancesUpdated"] = "notify:accountBalancesUpdated";
KeyringEvent["AccountAssetListUpdated"] = "notify:accountAssetListUpdated";
KeyringEvent["AccountTransactionsUpdated"] = "notify:accountTransactionsUpdated";
})(KeyringEvent || (exports.KeyringEvent = KeyringEvent = {}));
exports.AccountCreatedEventStruct = (0, keyring_utils_1.object)({
method: (0, superstruct_1.literal)(`${KeyringEvent.AccountCreated}`),
params: (0, keyring_utils_1.object)({
/**
* New account object.
*/
account: api_1.KeyringAccountStruct,
/**
* Account name suggestion provided to the MetaMask client.
*
* The keyring can suggest a name for the account, but it's up to the
* client to decide whether to use it. The keyring won't be informed if the
* client decides to use a different name.
*/
accountNameSuggestion: (0, keyring_utils_1.exactOptional)((0, superstruct_1.string)()),
/**
* Instructs MetaMask to display the add account confirmation dialog in the UI.
*
* **Note:** This is not guaranteed to be honored by the MetaMask client.
*/
displayConfirmation: (0, keyring_utils_1.exactOptional)((0, superstruct_1.boolean)()),
/**
* Instructs MetaMask to display the name confirmation dialog in the UI.
* Otherwise, the account will be added with the suggested name, if it's not
* already in use; if it is, a suffix will be appended to the name to make it
* unique.
*
* **Note:** This is not guaranteed to be honored by the MetaMask client.
*/
displayAccountNameSuggestion: (0, keyring_utils_1.exactOptional)((0, superstruct_1.boolean)()),
/**
* Metamask internal options.
*/
...api_1.MetaMaskOptionsStruct.schema,
}),
});
exports.AccountUpdatedEventStruct = (0, keyring_utils_1.object)({
method: (0, superstruct_1.literal)(`${KeyringEvent.AccountUpdated}`),
params: (0, keyring_utils_1.object)({
/**
* Updated account object.
*/
account: api_1.KeyringAccountStruct,
}),
});
exports.AccountDeletedEventStruct = (0, keyring_utils_1.object)({
method: (0, superstruct_1.literal)(`${KeyringEvent.AccountDeleted}`),
params: (0, keyring_utils_1.object)({
/**
* Deleted account ID.
*/
id: keyring_utils_1.UuidStruct,
}),
});
exports.RequestApprovedEventStruct = (0, keyring_utils_1.object)({
method: (0, superstruct_1.literal)(`${KeyringEvent.RequestApproved}`),
params: (0, keyring_utils_1.object)({
/**
* Request ID.
*/
id: keyring_utils_1.UuidStruct,
/**
* Request result.
*/
result: utils_1.JsonStruct,
}),
});
exports.RequestRejectedEventStruct = (0, keyring_utils_1.object)({
method: (0, superstruct_1.literal)(`${KeyringEvent.RequestRejected}`),
params: (0, keyring_utils_1.object)({
/**
* Request ID.
*/
id: keyring_utils_1.UuidStruct,
}),
});
// Assets related events:
// -----------------------------------------------------------------------------------------------
/**
* Event emitted when the balances of an account are updated.
*
* Only changes are reported.
*
* The Snap can choose to emit this event for multiple accounts at once.
*/
exports.AccountBalancesUpdatedEventStruct = (0, keyring_utils_1.object)({
method: (0, superstruct_1.literal)(`${KeyringEvent.AccountBalancesUpdated}`),
params: (0, keyring_utils_1.object)({
/**
* Balances updates of accounts owned by the Snap.
*/
balances: (0, superstruct_1.record)(
/**
* Account ID.
*/
keyring_utils_1.AccountIdStruct,
/**
* Mapping of each owned assets and their respective balances for that account.
*/
(0, superstruct_1.record)(
/**
* Asset type (CAIP-19).
*/
utils_1.CaipAssetTypeStruct,
/**
* Balance information for a given asset.
*/
api_1.FungibleAssetAmountStruct)),
}),
});
/**
* Event emitted when the transactions of an account are updated (added or
* changed).
*
* Only changes are reported.
*
* The Snap can choose to emit this event for multiple accounts at once.
*/
exports.AccountTransactionsUpdatedEventStruct = (0, keyring_utils_1.object)({
method: (0, superstruct_1.literal)(`${KeyringEvent.AccountTransactionsUpdated}`),
params: (0, keyring_utils_1.object)({
/**
* Transactions updates of accounts owned by the Snap.
*/
transactions: (0, superstruct_1.record)(
/**
* Account ID.
*/
keyring_utils_1.AccountIdStruct,
/**
* List of updated transactions for that account.
*/
(0, superstruct_1.array)(api_1.TransactionStruct)),
}),
});
/**
* Event emitted when the assets of an account are updated.
*
* Only changes are reported.
*
* The Snap can choose to emit this event for multiple accounts at once.
*/
exports.AccountAssetListUpdatedEventStruct = (0, keyring_utils_1.object)({
method: (0, superstruct_1.literal)(`${KeyringEvent.AccountAssetListUpdated}`),
params: (0, keyring_utils_1.object)({
/**
* Asset list update of accounts owned by the Snap.
*/
assets: (0, superstruct_1.record)(
/**
* Account ID.
*/
keyring_utils_1.AccountIdStruct,
/**
* Asset list changes for that account.
*/
(0, keyring_utils_1.object)({
/**
* New assets detected.
*/
added: (0, superstruct_1.array)(utils_1.CaipAssetTypeOrIdStruct),
/**
* Assets no longer available on that account.
*/
removed: (0, superstruct_1.array)(utils_1.CaipAssetTypeOrIdStruct),
})),
}),
});
//# sourceMappingURL=events.cjs.map