Socket
Socket
Sign inDemoInstall

@metamask/keyring-api

Package Overview
Dependencies
Maintainers
12
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/keyring-api - npm Package Compare versions

Comparing version 6.2.1 to 6.3.0

dist/api/account.d.ts

22

CHANGELOG.md

@@ -10,2 +10,21 @@ # Changelog

## [6.3.0]
### Added
- Add `getAccountBalances` method to `Keyring` interface ([#320](https://github.com/MetaMask/keyring-api/pull/320)).
- Add CAIP-19 types to `utils` ([#321](https://github.com/MetaMask/keyring-api/pull/321)).
### Changed
- Bump @metamask/snaps-sdk from 4.2.0 to 4.3.0 ([#323](https://github.com/MetaMask/keyring-api/pull/323)).
- Split `api.ts` into different files ([#319](https://github.com/MetaMask/keyring-api/pull/319)).
- Make the `KeyringAccount` type less rigid ([#311](https://github.com/MetaMask/keyring-api/pull/311)).
### Fixed
- Ensure that errors are JSON-serializable ([#162](https://github.com/MetaMask/keyring-api/pull/162)).
- Don't use internal types in the public API ([#312](https://github.com/MetaMask/keyring-api/pull/312)).
- Keep all ETH methods in the same `enum` ([#313](https://github.com/MetaMask/keyring-api/pull/313)).
## [6.2.1]

@@ -304,3 +323,4 @@

[Unreleased]: https://github.com/MetaMask/keyring-api/compare/v6.2.1...HEAD
[Unreleased]: https://github.com/MetaMask/keyring-api/compare/v6.3.0...HEAD
[6.3.0]: https://github.com/MetaMask/keyring-api/compare/v6.2.1...v6.3.0
[6.2.1]: https://github.com/MetaMask/keyring-api/compare/v6.2.0...v6.2.1

@@ -307,0 +327,0 @@ [6.2.0]: https://github.com/MetaMask/keyring-api/compare/v6.1.1...v6.2.0

11

dist/btc/types.d.ts

@@ -9,8 +9,2 @@ import type { Infer } from 'superstruct';

}
/**
* Supported Bitcoin account types.
*/
export declare enum BtcAccountType {
P2wpkh = "bip122:p2wpkh"
}
export declare const BtcP2wpkhAccountStruct: import("superstruct").Struct<{

@@ -24,2 +18,6 @@ type: "bip122:p2wpkh";

/**
* Account address.
*/
address: import("superstruct").Struct<string, null>;
/**
* Account type.

@@ -35,5 +33,4 @@ */

id: import("superstruct").Struct<string, null>;
address: import("superstruct").Struct<string, null>;
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
}>;
export declare type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BtcP2wpkhAccountStruct = exports.BtcAccountType = exports.BtcMethod = exports.BtcP2wpkhAddressStruct = void 0;
exports.BtcP2wpkhAccountStruct = exports.BtcMethod = exports.BtcP2wpkhAddressStruct = void 0;
const bech32_1 = require("bech32");
const superstruct_1 = require("superstruct");
const base_types_1 = require("../base-types");
const api_1 = require("../api");
const superstruct_2 = require("../superstruct");
exports.BtcP2wpkhAddressStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'BtcP2wpkhAddressStruct', (address) => {

@@ -24,15 +25,12 @@ try {

})(BtcMethod = exports.BtcMethod || (exports.BtcMethod = {}));
/**
* Supported Bitcoin account types.
*/
var BtcAccountType;
(function (BtcAccountType) {
BtcAccountType["P2wpkh"] = "bip122:p2wpkh";
})(BtcAccountType = exports.BtcAccountType || (exports.BtcAccountType = {}));
exports.BtcP2wpkhAccountStruct = (0, superstruct_1.object)({
...base_types_1.BaseAccount,
exports.BtcP2wpkhAccountStruct = (0, superstruct_2.object)({
...api_1.KeyringAccountStruct.schema,
/**
* Account address.
*/
address: exports.BtcP2wpkhAddressStruct,
/**
* Account type.
*/
type: (0, superstruct_1.literal)(`${BtcAccountType.P2wpkh}`),
type: (0, superstruct_1.literal)(`${api_1.BtcAccountType.P2wpkh}`),
/**

@@ -39,0 +37,0 @@ * Account supported methods.

@@ -38,4 +38,4 @@ import { type Infer } from 'superstruct';

value: string;
data: string;
to: string;
data: string;
}, {

@@ -42,0 +42,0 @@ /**

@@ -5,2 +5,3 @@ "use strict";

const superstruct_1 = require("../../superstruct");
const utils_1 = require("../../utils");
const types_1 = require("../types");

@@ -53,3 +54,3 @@ /**

dummySignature: types_1.EthBytesStruct,
bundlerUrl: superstruct_1.UrlStruct,
bundlerUrl: utils_1.UrlStruct,
});

@@ -56,0 +57,0 @@ exports.EthUserOperationPatchStruct = (0, superstruct_1.object)({

@@ -14,8 +14,3 @@ import type { Infer } from 'superstruct';

SignTypedDataV3 = "eth_signTypedData_v3",
SignTypedDataV4 = "eth_signTypedData_v4"
}
/**
* Supported Ethereum methods for ERC-4337 (Account Abstraction) accounts.
*/
export declare enum EthErc4337Method {
SignTypedDataV4 = "eth_signTypedData_v4",
PrepareUserOperation = "eth_prepareUserOperation",

@@ -25,9 +20,2 @@ PatchUserOperation = "eth_patchUserOperation",

}
/**
* Supported Ethereum account types.
*/
export declare enum EthAccountType {
Eoa = "eip155:eoa",
Erc4337 = "eip155:erc4337"
}
export declare const EthEoaAccountStruct: import("superstruct").Struct<{

@@ -41,2 +29,6 @@ type: "eip155:eoa";

/**
* Account address.
*/
address: import("superstruct").Struct<string, null>;
/**
* Account type.

@@ -57,3 +49,2 @@ */

id: import("superstruct").Struct<string, null>;
address: import("superstruct").Struct<string, null>;
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;

@@ -70,2 +61,6 @@ }>;

/**
* Account address.
*/
address: import("superstruct").Struct<string, null>;
/**
* Account type.

@@ -88,5 +83,4 @@ */

id: import("superstruct").Struct<string, null>;
address: import("superstruct").Struct<string, null>;
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
}>;
export declare type EthErc4337Account = Infer<typeof EthErc4337AccountStruct>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EthErc4337AccountStruct = exports.EthEoaAccountStruct = exports.EthAccountType = exports.EthErc4337Method = exports.EthMethod = exports.EthUint256Struct = exports.EthAddressStruct = exports.EthBytesStruct = void 0;
exports.EthErc4337AccountStruct = exports.EthEoaAccountStruct = exports.EthMethod = exports.EthUint256Struct = exports.EthAddressStruct = exports.EthBytesStruct = void 0;
const superstruct_1 = require("superstruct");
const base_types_1 = require("../base-types");
const api_1 = require("../api");
const superstruct_2 = require("../superstruct");

@@ -22,27 +22,17 @@ exports.EthBytesStruct = (0, superstruct_2.definePattern)('EthBytes', /^0x[0-9a-f]*$/iu);

EthMethod["SignTypedDataV4"] = "eth_signTypedData_v4";
// ERC-4337 methods
EthMethod["PrepareUserOperation"] = "eth_prepareUserOperation";
EthMethod["PatchUserOperation"] = "eth_patchUserOperation";
EthMethod["SignUserOperation"] = "eth_signUserOperation";
})(EthMethod = exports.EthMethod || (exports.EthMethod = {}));
/**
* Supported Ethereum methods for ERC-4337 (Account Abstraction) accounts.
*/
var EthErc4337Method;
(function (EthErc4337Method) {
// ERC-4337 methods
EthErc4337Method["PrepareUserOperation"] = "eth_prepareUserOperation";
EthErc4337Method["PatchUserOperation"] = "eth_patchUserOperation";
EthErc4337Method["SignUserOperation"] = "eth_signUserOperation";
})(EthErc4337Method = exports.EthErc4337Method || (exports.EthErc4337Method = {}));
/**
* Supported Ethereum account types.
*/
var EthAccountType;
(function (EthAccountType) {
EthAccountType["Eoa"] = "eip155:eoa";
EthAccountType["Erc4337"] = "eip155:erc4337";
})(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
exports.EthEoaAccountStruct = (0, superstruct_1.object)({
...base_types_1.BaseAccount,
exports.EthEoaAccountStruct = (0, superstruct_2.object)({
...api_1.KeyringAccountStruct.schema,
/**
* Account address.
*/
address: exports.EthAddressStruct,
/**
* Account type.
*/
type: (0, superstruct_1.literal)(`${EthAccountType.Eoa}`),
type: (0, superstruct_1.literal)(`${api_1.EthAccountType.Eoa}`),
/**

@@ -60,8 +50,12 @@ * Account supported methods.

});
exports.EthErc4337AccountStruct = (0, superstruct_1.object)({
...base_types_1.BaseAccount,
exports.EthErc4337AccountStruct = (0, superstruct_2.object)({
...api_1.KeyringAccountStruct.schema,
/**
* Account address.
*/
address: exports.EthAddressStruct,
/**
* Account type.
*/
type: (0, superstruct_1.literal)(`${EthAccountType.Erc4337}`),
type: (0, superstruct_1.literal)(`${api_1.EthAccountType.Erc4337}`),
/**

@@ -76,7 +70,7 @@ * Account supported methods.

`${EthMethod.SignTypedDataV4}`,
`${EthErc4337Method.PrepareUserOperation}`,
`${EthErc4337Method.PatchUserOperation}`,
`${EthErc4337Method.SignUserOperation}`,
`${EthMethod.PrepareUserOperation}`,
`${EthMethod.PatchUserOperation}`,
`${EthMethod.SignUserOperation}`,
])),
});
//# sourceMappingURL=types.js.map

@@ -1,7 +0,8 @@

import type { InternalAccountType } from '../internal';
import type { KeyringAccountType } from '../api';
/**
* Checks if the given type is an EVM account type.
*
* @param type - The type to check.
* @returns Returns true if the type is an EVM account type, false otherwise.
*/
export declare function isEvmAccountType(type: InternalAccountType | string): boolean;
export declare function isEvmAccountType(type: KeyringAccountType): boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEvmAccountType = void 0;
const types_1 = require("./types");
const api_1 = require("../api");
/**
* Checks if the given type is an EVM account type.
*
* @param type - The type to check.

@@ -11,5 +12,5 @@ * @returns Returns true if the type is an EVM account type, false otherwise.

function isEvmAccountType(type) {
return type === types_1.EthAccountType.Eoa || type === types_1.EthAccountType.Erc4337;
return type === api_1.EthAccountType.Eoa || type === api_1.EthAccountType.Erc4337;
}
exports.isEvmAccountType = isEvmAccountType;
//# sourceMappingURL=utils.js.map

@@ -12,39 +12,25 @@ import type { Infer } from 'superstruct';

export declare type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;
export declare const ListAccountsResponseStruct: import("superstruct").Struct<({
type: "bip122:p2wpkh";
export declare const ListAccountsResponseStruct: import("superstruct").Struct<{
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
methods: string[];
}[], import("superstruct").Struct<{
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
})[], import("superstruct").Struct<{
type: "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
}, null>>;
methods: string[];
}, {
id: import("superstruct").Struct<string, null>;
type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
"eip155:eoa": "eip155:eoa";
"eip155:erc4337": "eip155:erc4337";
"bip122:p2wpkh": "bip122:p2wpkh";
}>;
address: import("superstruct").Struct<string, null>;
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
}>>;
export declare type ListAccountsResponse = Infer<typeof ListAccountsResponseStruct>;

@@ -70,20 +56,18 @@ export declare const GetAccountRequestStruct: import("superstruct").Struct<{

export declare const GetAccountResponseStruct: import("superstruct").Struct<{
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
}, null>;
methods: string[];
}, {
id: import("superstruct").Struct<string, null>;
type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
"eip155:eoa": "eip155:eoa";
"eip155:erc4337": "eip155:erc4337";
"bip122:p2wpkh": "bip122:p2wpkh";
}>;
address: import("superstruct").Struct<string, null>;
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
}>;
export declare type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;

@@ -109,21 +93,45 @@ export declare const CreateAccountRequestStruct: import("superstruct").Struct<{

export declare const CreateAccountResponseStruct: import("superstruct").Struct<{
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
}, null>;
methods: string[];
}, {
id: import("superstruct").Struct<string, null>;
type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
"eip155:eoa": "eip155:eoa";
"eip155:erc4337": "eip155:erc4337";
"bip122:p2wpkh": "bip122:p2wpkh";
}>;
address: import("superstruct").Struct<string, null>;
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
}>;
export declare type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;
export declare const GetAccountBalancesRequestStruct: import("superstruct").Struct<{
jsonrpc: "2.0";
id: string | number | null;
method: "keyring_getAccountBalances";
params: {
id: string;
assets: string[];
};
}, {
method: import("superstruct").Struct<"keyring_getAccountBalances", "keyring_getAccountBalances">;
params: import("superstruct").Struct<{
id: string;
assets: string[];
}, {
id: import("superstruct").Struct<string, null>;
assets: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
}>;
jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
id: import("superstruct").Struct<string | number | null, null>;
}>;
export declare type GetAccountBalancesRequest = Infer<typeof GetAccountBalancesRequestStruct>;
export declare const GetAccountBalancesResponseStruct: import("superstruct").Struct<Record<string, {
amount: string;
unit: string;
}>, null>;
export declare type GetAccountBalancesResponse = Infer<typeof GetAccountBalancesResponseStruct>;
export declare const FilterAccountChainsStruct: import("superstruct").Struct<{

@@ -158,19 +166,7 @@ jsonrpc: "2.0";

account: {
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
methods: string[];
};

@@ -182,40 +178,26 @@ };

account: {
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
methods: string[];
};
}, {
account: import("superstruct").Struct<{
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
}, null>;
methods: string[];
}, {
id: import("superstruct").Struct<string, null>;
type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
"eip155:eoa": "eip155:eoa";
"eip155:erc4337": "eip155:erc4337";
"bip122:p2wpkh": "bip122:p2wpkh";
}>;
address: import("superstruct").Struct<string, null>;
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
}>;
}>;

@@ -280,4 +262,4 @@ jsonrpc: import("superstruct").Struct<"2.0", "2.0">;

id: string;
scope: string;
account: string;
scope: string;
request: {

@@ -289,4 +271,4 @@ method: string;

id: string;
scope: string;
account: string;
scope: string;
request: {

@@ -305,3 +287,3 @@ method: string;

method: import("superstruct").Struct<string, null>;
params: import("superstruct").Struct<import("..").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
params: import("superstruct").Struct<import("../superstruct").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
}>;

@@ -330,4 +312,4 @@ }>>;

id: string;
scope: string;
account: string;
scope: string;
request: {

@@ -346,3 +328,3 @@ method: string;

method: import("superstruct").Struct<string, null>;
params: import("superstruct").Struct<import("..").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
params: import("superstruct").Struct<import("../superstruct").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
}>;

@@ -357,4 +339,4 @@ }>;

id: string;
scope: string;
account: string;
scope: string;
request: {

@@ -369,4 +351,4 @@ method: string;

id: string;
scope: string;
account: string;
scope: string;
request: {

@@ -385,3 +367,3 @@ method: string;

method: import("superstruct").Struct<string, null>;
params: import("superstruct").Struct<import("..").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
params: import("superstruct").Struct<import("../superstruct").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
}>;

@@ -388,0 +370,0 @@ }>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RejectRequestResponseStruct = exports.RejectRequestRequestStruct = exports.ApproveRequestResponseStruct = exports.ApproveRequestRequestStruct = exports.SubmitRequestResponseStruct = exports.SubmitRequestRequestStruct = exports.GetRequestResponseStruct = exports.GetRequestRequestStruct = exports.ListRequestsResponseStruct = exports.ListRequestsRequestStruct = exports.ExportAccountResponseStruct = exports.ExportAccountRequestStruct = exports.DeleteAccountResponseStruct = exports.DeleteAccountRequestStruct = exports.UpdateAccountResponseStruct = exports.UpdateAccountRequestStruct = exports.FilterAccountChainsResponseStruct = exports.FilterAccountChainsStruct = exports.CreateAccountResponseStruct = exports.CreateAccountRequestStruct = exports.GetAccountResponseStruct = exports.GetAccountRequestStruct = exports.ListAccountsResponseStruct = exports.ListAccountsRequestStruct = void 0;
exports.RejectRequestResponseStruct = exports.RejectRequestRequestStruct = exports.ApproveRequestResponseStruct = exports.ApproveRequestRequestStruct = exports.SubmitRequestResponseStruct = exports.SubmitRequestRequestStruct = exports.GetRequestResponseStruct = exports.GetRequestRequestStruct = exports.ListRequestsResponseStruct = exports.ListRequestsRequestStruct = exports.ExportAccountResponseStruct = exports.ExportAccountRequestStruct = exports.DeleteAccountResponseStruct = exports.DeleteAccountRequestStruct = exports.UpdateAccountResponseStruct = exports.UpdateAccountRequestStruct = exports.FilterAccountChainsResponseStruct = exports.FilterAccountChainsStruct = exports.GetAccountBalancesResponseStruct = exports.GetAccountBalancesRequestStruct = exports.CreateAccountResponseStruct = exports.CreateAccountRequestStruct = exports.GetAccountResponseStruct = exports.GetAccountRequestStruct = exports.ListAccountsResponseStruct = exports.ListAccountsRequestStruct = void 0;
const utils_1 = require("@metamask/utils");
const superstruct_1 = require("superstruct");
const api_1 = require("../api");
const superstruct_2 = require("../superstruct");
const utils_2 = require("../utils");
const rpc_1 = require("./rpc");
const CommonHeader = {

@@ -14,3 +16,3 @@ jsonrpc: (0, superstruct_1.literal)('2.0'),

// List accounts
exports.ListAccountsRequestStruct = (0, superstruct_1.object)({
exports.ListAccountsRequestStruct = (0, superstruct_2.object)({
...CommonHeader,

@@ -22,6 +24,6 @@ method: (0, superstruct_1.literal)('keyring_listAccounts'),

// Get account
exports.GetAccountRequestStruct = (0, superstruct_1.object)({
exports.GetAccountRequestStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)('keyring_getAccount'),
params: (0, superstruct_1.object)({
params: (0, superstruct_2.object)({
id: utils_2.UuidStruct,

@@ -33,6 +35,6 @@ }),

// Create account
exports.CreateAccountRequestStruct = (0, superstruct_1.object)({
exports.CreateAccountRequestStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)('keyring_createAccount'),
params: (0, superstruct_1.object)({
params: (0, superstruct_2.object)({
options: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),

@@ -43,7 +45,18 @@ }),

// ----------------------------------------------------------------------------
// Get account balances
exports.GetAccountBalancesRequestStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)(`${rpc_1.KeyringRpcMethod.GetAccountBalances}`),
params: (0, superstruct_2.object)({
id: utils_2.UuidStruct,
assets: (0, superstruct_1.array)(utils_2.CaipAssetTypeStruct),
}),
});
exports.GetAccountBalancesResponseStruct = (0, superstruct_1.record)(utils_2.CaipAssetTypeStruct, api_1.BalanceStruct);
// ----------------------------------------------------------------------------
// Filter account chains
exports.FilterAccountChainsStruct = (0, superstruct_1.object)({
exports.FilterAccountChainsStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)('keyring_filterAccountChains'),
params: (0, superstruct_1.object)({
params: (0, superstruct_2.object)({
id: utils_2.UuidStruct,

@@ -56,6 +69,6 @@ chains: (0, superstruct_1.array)((0, superstruct_1.string)()),

// Update account
exports.UpdateAccountRequestStruct = (0, superstruct_1.object)({
exports.UpdateAccountRequestStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)('keyring_updateAccount'),
params: (0, superstruct_1.object)({
params: (0, superstruct_2.object)({
account: api_1.KeyringAccountStruct,

@@ -67,6 +80,6 @@ }),

// Delete account
exports.DeleteAccountRequestStruct = (0, superstruct_1.object)({
exports.DeleteAccountRequestStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)('keyring_deleteAccount'),
params: (0, superstruct_1.object)({
params: (0, superstruct_2.object)({
id: utils_2.UuidStruct,

@@ -78,6 +91,6 @@ }),

// Export account
exports.ExportAccountRequestStruct = (0, superstruct_1.object)({
exports.ExportAccountRequestStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)('keyring_exportAccount'),
params: (0, superstruct_1.object)({
params: (0, superstruct_2.object)({
id: utils_2.UuidStruct,

@@ -89,3 +102,3 @@ }),

// List requests
exports.ListRequestsRequestStruct = (0, superstruct_1.object)({
exports.ListRequestsRequestStruct = (0, superstruct_2.object)({
...CommonHeader,

@@ -97,6 +110,6 @@ method: (0, superstruct_1.literal)('keyring_listRequests'),

// Get request
exports.GetRequestRequestStruct = (0, superstruct_1.object)({
exports.GetRequestRequestStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)('keyring_getRequest'),
params: (0, superstruct_1.object)({
params: (0, superstruct_2.object)({
id: utils_2.UuidStruct,

@@ -108,3 +121,3 @@ }),

// Submit request
exports.SubmitRequestRequestStruct = (0, superstruct_1.object)({
exports.SubmitRequestRequestStruct = (0, superstruct_2.object)({
...CommonHeader,

@@ -117,6 +130,6 @@ method: (0, superstruct_1.literal)('keyring_submitRequest'),

// Approve request
exports.ApproveRequestRequestStruct = (0, superstruct_1.object)({
exports.ApproveRequestRequestStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)('keyring_approveRequest'),
params: (0, superstruct_1.object)({
params: (0, superstruct_2.object)({
id: utils_2.UuidStruct,

@@ -129,6 +142,6 @@ data: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),

// Reject request
exports.RejectRequestRequestStruct = (0, superstruct_1.object)({
exports.RejectRequestRequestStruct = (0, superstruct_2.object)({
...CommonHeader,
method: (0, superstruct_1.literal)('keyring_rejectRequest'),
params: (0, superstruct_1.object)({
params: (0, superstruct_2.object)({
id: utils_2.UuidStruct,

@@ -135,0 +148,0 @@ }),

@@ -5,19 +5,7 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{

account: {
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
methods: string[];
};

@@ -31,19 +19,7 @@ accountNameSuggestion?: string;

account: {
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
methods: string[];
};

@@ -57,20 +33,18 @@ accountNameSuggestion?: string;

account: import("superstruct").Struct<{
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
}, null>;
methods: string[];
}, {
id: import("superstruct").Struct<string, null>;
type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
"eip155:eoa": "eip155:eoa";
"eip155:erc4337": "eip155:erc4337";
"bip122:p2wpkh": "bip122:p2wpkh";
}>;
address: import("superstruct").Struct<string, null>;
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
}>;
/**

@@ -95,19 +69,7 @@ * Account name suggestion provided to the MetaMask client.

account: {
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
methods: string[];
};

@@ -119,19 +81,7 @@ };

account: {
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
methods: string[];
};

@@ -143,20 +93,18 @@ }, {

account: import("superstruct").Struct<{
type: "bip122:p2wpkh";
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: "btc_sendmany"[];
} | {
type: "eip155:eoa";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
} | {
type: "eip155:erc4337";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
}, null>;
methods: string[];
}, {
id: import("superstruct").Struct<string, null>;
type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
"eip155:eoa": "eip155:eoa";
"eip155:erc4337": "eip155:erc4337";
"bip122:p2wpkh": "bip122:p2wpkh";
}>;
address: import("superstruct").Struct<string, null>;
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
}>;
}>;

@@ -163,0 +111,0 @@ }>;

@@ -8,2 +8,3 @@ /**

CreateAccount = "keyring_createAccount",
GetAccountBalances = "keyring_getAccountBalances",
FilterAccountChains = "keyring_filterAccountChains",

@@ -10,0 +11,0 @@ UpdateAccount = "keyring_updateAccount",

@@ -12,2 +12,3 @@ "use strict";

KeyringRpcMethod["CreateAccount"] = "keyring_createAccount";
KeyringRpcMethod["GetAccountBalances"] = "keyring_getAccountBalances";
KeyringRpcMethod["FilterAccountChains"] = "keyring_filterAccountChains";

@@ -14,0 +15,0 @@ KeyringRpcMethod["UpdateAccount"] = "keyring_updateAccount";

import type { Infer, Struct } from 'superstruct';
import { BtcAccountType } from '../btc/types';
import { EthAccountType } from '../eth/types';
import { BtcAccountType, EthAccountType } from '../api';
export declare type InternalAccountType = EthAccountType | BtcAccountType;

@@ -72,2 +71,3 @@ export declare const InternalAccountMetadataStruct: Struct<{

}, {
address: Struct<string, null>;
type: Struct<"eip155:eoa", "eip155:eoa">;

@@ -83,3 +83,2 @@ methods: Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {

id: Struct<string, null>;
address: Struct<string, null>;
options: Struct<Record<string, import("@metamask/utils").Json>, null>;

@@ -139,2 +138,3 @@ } & {

}, {
address: Struct<string, null>;
type: Struct<"eip155:erc4337", "eip155:erc4337">;

@@ -152,3 +152,2 @@ methods: Struct<("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], Struct<"personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {

id: Struct<string, null>;
address: Struct<string, null>;
options: Struct<Record<string, import("@metamask/utils").Json>, null>;

@@ -208,2 +207,3 @@ } & {

}, {
address: Struct<string, null>;
type: Struct<"bip122:p2wpkh", "bip122:p2wpkh">;

@@ -214,3 +214,2 @@ methods: Struct<"btc_sendmany"[], Struct<"btc_sendmany", {

id: Struct<string, null>;
address: Struct<string, null>;
options: Struct<Record<string, import("@metamask/utils").Json>, null>;

@@ -255,3 +254,63 @@ } & {

export declare type InternalAccountTypes = InternalEthEoaAccount | InternalEthErc4337Account | InternalBtcP2wpkhAccount;
export declare const InternalAccountStruct: Struct<InternalAccountTypes, null>;
export declare const InternalAccountStruct: Struct<{
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
id: string;
address: string;
options: Record<string, import("@metamask/utils").Json>;
methods: string[];
metadata: {
name: string;
importTime: number;
keyring: {
type: string;
};
snap?: {
id: string;
name: string;
enabled: boolean;
};
lastSelected?: number;
};
}, {
metadata: Struct<{
name: string;
importTime: number;
keyring: {
type: string;
};
snap?: {
id: string;
name: string;
enabled: boolean;
};
lastSelected?: number;
}, {
name: Struct<string, null>;
snap: Struct<import("../superstruct").ExactOptionalTag | {
id: string;
name: string;
enabled: boolean;
}, {
id: Struct<string, null>;
enabled: Struct<boolean, null>;
name: Struct<string, null>;
}>;
lastSelected: Struct<number | import("../superstruct").ExactOptionalTag, null>;
importTime: Struct<number, null>;
keyring: Struct<{
type: string;
}, {
type: Struct<string, null>;
}>;
}>;
id: Struct<string, null>;
type: Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
"eip155:eoa": "eip155:eoa";
"eip155:erc4337": "eip155:erc4337";
"bip122:p2wpkh": "bip122:p2wpkh";
}>;
address: Struct<string, null>;
options: Struct<Record<string, import("@metamask/utils").Json>, null>;
methods: Struct<string[], Struct<string, null>>;
}>;
/**

@@ -258,0 +317,0 @@ * Internal account representation.

@@ -28,3 +28,3 @@ "use strict";

* @param accountStruct - An account `superstruct` object.
* @returns The `InternalAccount` assocaited to `accountStruct`.
* @returns The `InternalAccount` associated to `accountStruct`.
*/

@@ -41,12 +41,10 @@ function asInternalAccountStruct(accountStruct) {

exports.InternalAccountStructs = {
[`${types_2.EthAccountType.Eoa}`]: exports.InternalEthEoaAccountStruct,
[`${types_2.EthAccountType.Erc4337}`]: exports.InternalEthErc4337AccountStruct,
[`${types_1.BtcAccountType.P2wpkh}`]: exports.InternalBtcP2wpkhAccountStruct,
[`${api_1.EthAccountType.Eoa}`]: exports.InternalEthEoaAccountStruct,
[`${api_1.EthAccountType.Erc4337}`]: exports.InternalEthErc4337AccountStruct,
[`${api_1.BtcAccountType.P2wpkh}`]: exports.InternalBtcP2wpkhAccountStruct,
};
exports.InternalAccountStruct = (0, superstruct_1.define)('InternalAccount', (value) => {
const account = (0, superstruct_1.mask)(value, api_1.BaseKeyringAccountStruct);
// At this point, we know that `value.type` can be used as an index for `KeyringAccountStructs`
const [error] = (0, superstruct_1.validate)(value, exports.InternalAccountStructs[account.type]);
return error ?? true;
exports.InternalAccountStruct = (0, superstruct_2.object)({
...api_1.KeyringAccountStruct.schema,
...exports.InternalAccountMetadataStruct.schema,
});
//# sourceMappingURL=types.js.map

@@ -20,3 +20,3 @@ "use strict";

const rpc_1 = require("./internal/rpc");
const utils_1 = require("./utils");
const superstruct_2 = require("./superstruct");
class KeyringClient {

@@ -34,3 +34,3 @@ /**

async listAccounts() {
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
method: rpc_1.KeyringRpcMethod.ListAccounts,

@@ -40,3 +40,3 @@ }), api_1.ListAccountsResponseStruct);

async getAccount(id) {
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
method: rpc_1.KeyringRpcMethod.GetAccount,

@@ -47,3 +47,3 @@ params: { id },

async createAccount(options = {}) {
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
method: rpc_1.KeyringRpcMethod.CreateAccount,

@@ -54,3 +54,3 @@ params: { options },

async filterAccountChains(id, chains) {
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
method: rpc_1.KeyringRpcMethod.FilterAccountChains,

@@ -73,3 +73,3 @@ params: { id, chains },

async exportAccount(id) {
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
method: rpc_1.KeyringRpcMethod.ExportAccount,

@@ -80,3 +80,3 @@ params: { id },

async listRequests() {
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
method: rpc_1.KeyringRpcMethod.ListRequests,

@@ -86,3 +86,3 @@ }), api_1.ListRequestsResponseStruct);

async getRequest(id) {
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
method: rpc_1.KeyringRpcMethod.GetRequest,

@@ -93,3 +93,3 @@ params: { id },

async submitRequest(request) {
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
method: rpc_1.KeyringRpcMethod.SubmitRequest,

@@ -96,0 +96,0 @@ params: request,

@@ -13,6 +13,18 @@ import type { Json } from '@metamask/utils';

*
* This function is meant to be used as a handler for Keyring JSON-RPC requests
* in an Accounts Snap.
*
* @param keyring - Keyring instance.
* @param request - Keyring JSON-RPC request.
* @returns A promise that resolves to the keyring response.
* @example
* ```ts
* export const onKeyringRequest: OnKeyringRequestHandler = async ({
* origin,
* request,
* }) => {
* return await handleKeyringRequest(keyring, request);
* };
* ```
*/
export declare function handleKeyringRequest(keyring: Keyring, request: JsonRpcRequest): Promise<Json | void>;

@@ -18,3 +18,4 @@ "use strict";

/**
* Handles a keyring JSON-RPC request.
* Inner function that dispatches JSON-RPC request to the associated Keyring
* methods.
*

@@ -25,3 +26,3 @@ * @param keyring - Keyring instance.

*/
async function handleKeyringRequest(keyring, request) {
async function dispatchRequest(keyring, request) {
// We first have to make sure that the request is a valid JSON-RPC request so

@@ -43,2 +44,9 @@ // we can check its method name.

}
case rpc_1.KeyringRpcMethod.GetAccountBalances: {
if (keyring.getAccountBalances === undefined) {
throw new MethodNotSupportedError(request.method);
}
(0, superstruct_1.assert)(request, api_1.GetAccountBalancesRequestStruct);
return keyring.getAccountBalances(request.params.id, request.params.assets);
}
case rpc_1.KeyringRpcMethod.FilterAccountChains: {

@@ -100,3 +108,33 @@ (0, superstruct_1.assert)(request, api_1.FilterAccountChainsStruct);

}
/**
* Handles a keyring JSON-RPC request.
*
* This function is meant to be used as a handler for Keyring JSON-RPC requests
* in an Accounts Snap.
*
* @param keyring - Keyring instance.
* @param request - Keyring JSON-RPC request.
* @returns A promise that resolves to the keyring response.
* @example
* ```ts
* export const onKeyringRequest: OnKeyringRequestHandler = async ({
* origin,
* request,
* }) => {
* return await handleKeyringRequest(keyring, request);
* };
* ```
*/
async function handleKeyringRequest(keyring, request) {
try {
return await dispatchRequest(keyring, request);
}
catch (error) {
const message = error instanceof Error && typeof error.message === 'string'
? error.message
: 'An unknown error occurred while handling the keyring request';
throw new Error(message);
}
}
exports.handleKeyringRequest = handleKeyringRequest;
//# sourceMappingURL=rpc-handler.js.map

@@ -73,8 +73,13 @@ import type { Infer } from 'superstruct';

/**
* Validates if a given value is a valid URL.
* Assert that a value is valid according to a struct.
*
* @param value - The value to be validated.
* @returns A boolean indicating if the value is a valid URL.
* It is similar to superstruct's mask function, but it does not ignore extra
* properties.
*
* @param value - Value to check.
* @param struct - Struct to validate the value against.
* @param message - Error message to throw if the value is not valid.
* @returns The value if it is valid.
*/
export declare const UrlStruct: Struct<string, null>;
export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UrlStruct = exports.definePattern = exports.exactOptional = exports.object = void 0;
exports.strictMask = exports.definePattern = exports.exactOptional = exports.object = void 0;
const superstruct_1 = require("superstruct");

@@ -66,17 +66,17 @@ /**

/**
* Validates if a given value is a valid URL.
* Assert that a value is valid according to a struct.
*
* @param value - The value to be validated.
* @returns A boolean indicating if the value is a valid URL.
* It is similar to superstruct's mask function, but it does not ignore extra
* properties.
*
* @param value - Value to check.
* @param struct - Struct to validate the value against.
* @param message - Error message to throw if the value is not valid.
* @returns The value if it is valid.
*/
exports.UrlStruct = (0, superstruct_1.define)('Url', (value) => {
let url;
try {
url = new URL(value);
}
catch (_) {
return false;
}
return url.protocol === 'http:' || url.protocol === 'https:';
});
function strictMask(value, struct, message) {
(0, superstruct_1.assert)(value, struct, message);
return value;
}
exports.strictMask = strictMask;
//# sourceMappingURL=superstruct.js.map
{
"name": "@metamask/keyring-api",
"version": "6.2.1",
"version": "6.3.0",
"description": "MetaMask Keyring API",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc