@metamask/keyring-api
Version:
MetaMask Keyring API
122 lines • 4.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyringAccountOptionsStruct = exports.KeyringAccountEntropyOptionsStruct = exports.KeyringAccountEntropyPrivateKeyOptionsStruct = exports.KeyringAccountEntropyMnemonicOptionsStruct = exports.KeyringAccountEntropyTypeOption = void 0;
const keyring_utils_1 = require("@metamask/keyring-utils");
const superstruct_1 = require("@metamask/superstruct");
const utils_1 = require("@metamask/utils");
/**
* Keyring account entropy valid types.
*/
var KeyringAccountEntropyTypeOption;
(function (KeyringAccountEntropyTypeOption) {
/**
* Indicates that the account was created from a mnemonic phrase.
*/
KeyringAccountEntropyTypeOption["Mnemonic"] = "mnemonic";
/**
* Indicates that the account was imported from a private key.
*/
KeyringAccountEntropyTypeOption["PrivateKey"] = "private-key";
})(KeyringAccountEntropyTypeOption || (exports.KeyringAccountEntropyTypeOption = KeyringAccountEntropyTypeOption = {}));
/**
* Keyring account options struct for mnemonics (BIP-44).
*/
exports.KeyringAccountEntropyMnemonicOptionsStruct = (0, superstruct_1.object)({
/**
* Indicates that the account was created from a mnemonic phrase.
*/
type: (0, superstruct_1.literal)(`${KeyringAccountEntropyTypeOption.Mnemonic}`),
/**
* The ID of the entropy source.
*/
id: (0, superstruct_1.string)(), // TODO: Define a struct for entropy source.
/**
* The BIP-44 derivation path used to derive the account.
*/
derivationPath: (0, superstruct_1.string)(),
/**
* Index used to group accounts in the UI.
*
* Accounts sharing the same `groupIndex` are displayed together as a
* multichain account group.
*/
groupIndex: (0, superstruct_1.number)(),
});
/**
* Keyring account options struct for private keys.
*/
exports.KeyringAccountEntropyPrivateKeyOptionsStruct = (0, superstruct_1.object)({
/**
* Indicates that the account was imported from a private key.
*/
type: (0, superstruct_1.literal)(`${KeyringAccountEntropyTypeOption.PrivateKey}`),
});
/**
* Keyring account entropy options struct.
*/
exports.KeyringAccountEntropyOptionsStruct = (0, keyring_utils_1.selectiveUnion)((value) => {
return (0, utils_1.isPlainObject)(value) &&
value.type === KeyringAccountEntropyTypeOption.PrivateKey
? exports.KeyringAccountEntropyPrivateKeyOptionsStruct
: exports.KeyringAccountEntropyMnemonicOptionsStruct;
});
/**
* Keyring options struct. This represents various options for a Keyring account object.
*
* See {@link KeyringAccountEntropyMnemonicOptionsStruct} and
* {@link KeyringAccountEntropyPrivateKeyOptionsStruct}.
*
* @example
* ```ts
* {
* entropy: {
* type: 'mnemonic',
* id: '01K0BX6VDR5DPDPGGNA8PZVBVB',
* derivationPath: "m/44'/60'/0'/0/0",
* groupIndex: 0,
* },
* }
* ```
*
* @example
* ```ts
* {
* entropy: {
* type: 'private-key',
* },
* exportable: true,
* }
* ```
*
* @example
* ```ts
* {
* some: {
* untyped: 'options',
* something: true,
* },
* }
* ```
*/
exports.KeyringAccountOptionsStruct = (0, superstruct_1.intersection)([
// Non-Typed options (retro-compatibility):
(0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
// Typed options. We use `type` instead of `object` here, to allow
// extra properties. Also, since we use `record` + `intersection` we
// are guaranteed that all field values will match the `JsonStruct`.
//
// READ THIS CAREFULLY:
// Previous options that can be matched by this struct will be breaking
// existing keyring account options.
(0, keyring_utils_1.type)({
/**
* Entropy options.
*/
entropy: (0, keyring_utils_1.exactOptional)(exports.KeyringAccountEntropyOptionsStruct),
/**
* Indicates whether the account can be exported.
*/
exportable: (0, keyring_utils_1.exactOptional)((0, superstruct_1.boolean)()),
}),
]);
//# sourceMappingURL=account-options.cjs.map