@metamask-previews/keyring-api 8.1.0-preview-37040eb → 8.1.0-preview-399ef96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/JsonRpcRequest.d.ts +17 -0
- package/dist/JsonRpcRequest.d.ts.map +1 -0
- package/dist/JsonRpcRequest.js +13 -0
- package/dist/JsonRpcRequest.js.map +1 -0
- package/dist/KeyringClient.d.ts +29 -0
- package/dist/KeyringClient.d.ts.map +1 -0
- package/dist/KeyringClient.js +124 -0
- package/dist/KeyringClient.js.map +1 -0
- package/dist/KeyringSnapRpcClient.d.ts +40 -0
- package/dist/KeyringSnapRpcClient.d.ts.map +1 -0
- package/dist/KeyringSnapRpcClient.js +68 -0
- package/dist/KeyringSnapRpcClient.js.map +1 -0
- package/dist/api/account.d.ts +63 -0
- package/dist/api/account.d.ts.map +1 -0
- package/dist/api/account.js +56 -0
- package/dist/api/account.js.map +1 -0
- package/dist/api/balance.d.ts +10 -0
- package/dist/api/balance.d.ts.map +1 -0
- package/dist/api/balance.js +11 -0
- package/dist/api/balance.js.map +1 -0
- package/dist/api/caip.d.ts +38 -0
- package/dist/api/caip.d.ts.map +1 -0
- package/dist/api/caip.js +48 -0
- package/dist/api/caip.js.map +1 -0
- package/dist/api/export.d.ts +9 -0
- package/dist/api/export.d.ts.map +1 -0
- package/dist/api/export.js +7 -0
- package/dist/api/export.js.map +1 -0
- package/dist/api/index.d.ts +8 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +24 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/keyring.d.ts +160 -0
- package/dist/api/keyring.d.ts.map +1 -0
- package/dist/api/keyring.js +3 -0
- package/dist/api/keyring.js.map +1 -0
- package/dist/api/request.d.ts +40 -0
- package/dist/api/request.d.ts.map +1 -0
- package/dist/api/request.js +29 -0
- package/dist/api/request.js.map +1 -0
- package/dist/api/response.d.ts +25 -0
- package/dist/api/response.d.ts.map +1 -0
- package/dist/api/response.js +44 -0
- package/dist/api/response.js.map +1 -0
- package/dist/btc/index.d.ts +2 -0
- package/dist/btc/index.d.ts.map +1 -0
- package/dist/btc/index.js +18 -0
- package/dist/btc/index.js.map +1 -0
- package/dist/btc/types.d.ts +34 -0
- package/dist/btc/types.d.ts.map +1 -0
- package/dist/btc/types.js +40 -0
- package/dist/btc/types.js.map +1 -0
- package/dist/contexts.d.ts +8 -0
- package/dist/contexts.d.ts.map +1 -0
- package/dist/contexts.js +3 -0
- package/dist/contexts.js.map +1 -0
- package/dist/eth/erc4337/index.d.ts +2 -0
- package/dist/eth/erc4337/index.d.ts.map +1 -0
- package/dist/eth/erc4337/index.js +18 -0
- package/dist/eth/erc4337/index.js.map +1 -0
- package/dist/eth/erc4337/types.d.ts +97 -0
- package/dist/eth/erc4337/types.d.ts.map +1 -0
- package/dist/eth/erc4337/types.js +61 -0
- package/dist/eth/erc4337/types.js.map +1 -0
- package/dist/eth/index.d.ts +4 -0
- package/dist/eth/index.d.ts.map +1 -0
- package/dist/eth/index.js +20 -0
- package/dist/eth/index.js.map +1 -0
- package/dist/eth/types.d.ts +81 -0
- package/dist/eth/types.d.ts.map +1 -0
- package/dist/eth/types.js +73 -0
- package/dist/eth/types.js.map +1 -0
- package/dist/eth/utils.d.ts +9 -0
- package/dist/eth/utils.d.ts.map +1 -0
- package/dist/eth/utils.js +15 -0
- package/dist/eth/utils.js.map +1 -0
- package/dist/events.d.ts +11 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +17 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/api.d.ts +416 -0
- package/dist/internal/api.d.ts.map +1 -0
- package/dist/internal/api.js +139 -0
- package/dist/internal/api.js.map +1 -0
- package/dist/internal/eth/EthKeyring.d.ts +34 -0
- package/dist/internal/eth/EthKeyring.d.ts.map +1 -0
- package/dist/internal/eth/EthKeyring.js +3 -0
- package/dist/internal/eth/EthKeyring.js.map +1 -0
- package/dist/internal/eth/index.d.ts +2 -0
- package/dist/internal/eth/index.d.ts.map +1 -0
- package/dist/internal/eth/index.js +18 -0
- package/dist/internal/eth/index.js.map +1 -0
- package/dist/internal/events.d.ts +160 -0
- package/dist/internal/events.d.ts.map +1 -0
- package/dist/internal/events.js +72 -0
- package/dist/internal/events.js.map +1 -0
- package/dist/internal/index.d.ts +6 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +22 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/internal/rpc.d.ts +26 -0
- package/dist/internal/rpc.d.ts.map +1 -0
- package/dist/internal/rpc.js +33 -0
- package/dist/internal/rpc.js.map +1 -0
- package/dist/internal/types.d.ts +331 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +49 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/rpc-handler.d.ts +30 -0
- package/dist/rpc-handler.d.ts.map +1 -0
- package/dist/rpc-handler.js +136 -0
- package/dist/rpc-handler.js.map +1 -0
- package/dist/snap-utils.d.ts +12 -0
- package/dist/snap-utils.d.ts.map +1 -0
- package/dist/snap-utils.js +21 -0
- package/dist/snap-utils.js.map +1 -0
- package/dist/superstruct.d.ts +84 -0
- package/dist/superstruct.d.ts.map +1 -0
- package/dist/superstruct.js +81 -0
- package/dist/superstruct.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/types.d.ts +18 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +29 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/typing.d.ts +33 -0
- package/dist/utils/typing.d.ts.map +1 -0
- package/dist/utils/typing.js +21 -0
- package/dist/utils/typing.js.map +1 -0
- package/package.json +1 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Infer } from '@metamask/superstruct';
|
|
2
|
+
export declare const JsonRpcRequestStruct: import("@metamask/superstruct").Struct<{
|
|
3
|
+
jsonrpc: "2.0";
|
|
4
|
+
id: string | number | null;
|
|
5
|
+
method: string;
|
|
6
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
|
7
|
+
}, {
|
|
8
|
+
jsonrpc: import("@metamask/superstruct").Struct<"2.0", "2.0">;
|
|
9
|
+
id: import("@metamask/superstruct").Struct<string | number | null, null>;
|
|
10
|
+
method: import("@metamask/superstruct").Struct<string, null>;
|
|
11
|
+
params: import("@metamask/superstruct").Struct<import("./superstruct").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* JSON-RPC request type.
|
|
15
|
+
*/
|
|
16
|
+
export declare type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;
|
|
17
|
+
//# sourceMappingURL=JsonRpcRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonRpcRequest.d.ts","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAKnD,eAAO,MAAM,oBAAoB;;;;;;;;;;EAO/B,CAAC;AAEH;;GAEG;AACH,oBAAY,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonRpcRequestStruct = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
const superstruct_2 = require("./superstruct");
|
|
7
|
+
exports.JsonRpcRequestStruct = (0, superstruct_2.object)({
|
|
8
|
+
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
|
9
|
+
id: (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)(), (0, superstruct_1.literal)(null)]),
|
|
10
|
+
method: (0, superstruct_1.string)(),
|
|
11
|
+
params: (0, superstruct_2.exactOptional)((0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)])),
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=JsonRpcRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonRpcRequest.js","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,uDAO+B;AAE/B,2CAA6C;AAE7C,+CAAsD;AAEzC,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,MAAM,EAAE,IAAA,2BAAa,EACnB,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC,CACzD;CACF,CAAC,CAAC","sourcesContent":["import {\n array,\n literal,\n number,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { exactOptional, object } from './superstruct';\n\nexport const JsonRpcRequestStruct = object({\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n});\n\n/**\n * JSON-RPC request type.\n */\nexport type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Json } from '@metamask/utils';
|
|
2
|
+
import type { Keyring, KeyringAccount, KeyringRequest, KeyringAccountData, KeyringResponse, CaipAssetType, Balance } from './api';
|
|
3
|
+
import type { JsonRpcRequest } from './JsonRpcRequest';
|
|
4
|
+
export declare type Sender = {
|
|
5
|
+
send(request: JsonRpcRequest): Promise<Json>;
|
|
6
|
+
};
|
|
7
|
+
export declare class KeyringClient implements Keyring {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new instance of `KeyringClient`.
|
|
11
|
+
*
|
|
12
|
+
* @param sender - The `Sender` instance to use to send requests to the snap.
|
|
13
|
+
*/
|
|
14
|
+
constructor(sender: Sender);
|
|
15
|
+
listAccounts(): Promise<KeyringAccount[]>;
|
|
16
|
+
getAccount(id: string): Promise<KeyringAccount>;
|
|
17
|
+
getAccountBalances(id: string, assets: CaipAssetType[]): Promise<Record<CaipAssetType, Balance>>;
|
|
18
|
+
createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;
|
|
19
|
+
filterAccountChains(id: string, chains: string[]): Promise<string[]>;
|
|
20
|
+
updateAccount(account: KeyringAccount): Promise<void>;
|
|
21
|
+
deleteAccount(id: string): Promise<void>;
|
|
22
|
+
exportAccount(id: string): Promise<KeyringAccountData>;
|
|
23
|
+
listRequests(): Promise<KeyringRequest[]>;
|
|
24
|
+
getRequest(id: string): Promise<KeyringRequest>;
|
|
25
|
+
submitRequest(request: KeyringRequest): Promise<KeyringResponse>;
|
|
26
|
+
approveRequest(id: string, data?: Record<string, Json>): Promise<void>;
|
|
27
|
+
rejectRequest(id: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=KeyringClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyringClient.d.ts","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,OAAO,EACR,MAAM,OAAO,CAAC;AAiBf,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,oBAAY,MAAM,GAAG;IACnB,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF,qBAAa,aAAc,YAAW,OAAO;;IAG3C;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAkBpB,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IASzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU/C,kBAAkB,CACtB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,aAAa,EAAE,GACtB,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAUpC,aAAa,CACjB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GACjC,OAAO,CAAC,cAAc,CAAC;IAUpB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAUpE,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxC,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAUtD,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IASzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU/C,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAUhE,cAAc,CAClB,EAAE,EAAE,MAAM,EACV,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GAC9B,OAAO,CAAC,IAAI,CAAC;IAUV,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS/C"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _KeyringClient_instances, _KeyringClient_sender, _KeyringClient_send;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.KeyringClient = void 0;
|
|
16
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
17
|
+
const uuid_1 = require("uuid");
|
|
18
|
+
const api_1 = require("./internal/api");
|
|
19
|
+
const rpc_1 = require("./internal/rpc");
|
|
20
|
+
const superstruct_2 = require("./superstruct");
|
|
21
|
+
class KeyringClient {
|
|
22
|
+
/**
|
|
23
|
+
* Create a new instance of `KeyringClient`.
|
|
24
|
+
*
|
|
25
|
+
* @param sender - The `Sender` instance to use to send requests to the snap.
|
|
26
|
+
*/
|
|
27
|
+
constructor(sender) {
|
|
28
|
+
_KeyringClient_instances.add(this);
|
|
29
|
+
_KeyringClient_sender.set(this, void 0);
|
|
30
|
+
__classPrivateFieldSet(this, _KeyringClient_sender, sender, "f");
|
|
31
|
+
}
|
|
32
|
+
async listAccounts() {
|
|
33
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
34
|
+
method: rpc_1.KeyringRpcMethod.ListAccounts,
|
|
35
|
+
}), api_1.ListAccountsResponseStruct);
|
|
36
|
+
}
|
|
37
|
+
async getAccount(id) {
|
|
38
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
39
|
+
method: rpc_1.KeyringRpcMethod.GetAccount,
|
|
40
|
+
params: { id },
|
|
41
|
+
}), api_1.GetAccountResponseStruct);
|
|
42
|
+
}
|
|
43
|
+
async getAccountBalances(id, assets) {
|
|
44
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
45
|
+
method: rpc_1.KeyringRpcMethod.GetAccountBalances,
|
|
46
|
+
params: { id, assets },
|
|
47
|
+
}), api_1.GetAccountBalancesResponseStruct);
|
|
48
|
+
}
|
|
49
|
+
async createAccount(options = {}) {
|
|
50
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
51
|
+
method: rpc_1.KeyringRpcMethod.CreateAccount,
|
|
52
|
+
params: { options },
|
|
53
|
+
}), api_1.CreateAccountResponseStruct);
|
|
54
|
+
}
|
|
55
|
+
async filterAccountChains(id, chains) {
|
|
56
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
57
|
+
method: rpc_1.KeyringRpcMethod.FilterAccountChains,
|
|
58
|
+
params: { id, chains },
|
|
59
|
+
}), api_1.FilterAccountChainsResponseStruct);
|
|
60
|
+
}
|
|
61
|
+
async updateAccount(account) {
|
|
62
|
+
(0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
63
|
+
method: rpc_1.KeyringRpcMethod.UpdateAccount,
|
|
64
|
+
params: { account },
|
|
65
|
+
}), api_1.UpdateAccountResponseStruct);
|
|
66
|
+
}
|
|
67
|
+
async deleteAccount(id) {
|
|
68
|
+
(0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
69
|
+
method: rpc_1.KeyringRpcMethod.DeleteAccount,
|
|
70
|
+
params: { id },
|
|
71
|
+
}), api_1.DeleteAccountResponseStruct);
|
|
72
|
+
}
|
|
73
|
+
async exportAccount(id) {
|
|
74
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
75
|
+
method: rpc_1.KeyringRpcMethod.ExportAccount,
|
|
76
|
+
params: { id },
|
|
77
|
+
}), api_1.ExportAccountResponseStruct);
|
|
78
|
+
}
|
|
79
|
+
async listRequests() {
|
|
80
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
81
|
+
method: rpc_1.KeyringRpcMethod.ListRequests,
|
|
82
|
+
}), api_1.ListRequestsResponseStruct);
|
|
83
|
+
}
|
|
84
|
+
async getRequest(id) {
|
|
85
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
86
|
+
method: rpc_1.KeyringRpcMethod.GetRequest,
|
|
87
|
+
params: { id },
|
|
88
|
+
}), api_1.GetRequestResponseStruct);
|
|
89
|
+
}
|
|
90
|
+
async submitRequest(request) {
|
|
91
|
+
return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
92
|
+
method: rpc_1.KeyringRpcMethod.SubmitRequest,
|
|
93
|
+
params: request,
|
|
94
|
+
}), api_1.SubmitRequestResponseStruct);
|
|
95
|
+
}
|
|
96
|
+
async approveRequest(id, data = {}) {
|
|
97
|
+
(0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
98
|
+
method: rpc_1.KeyringRpcMethod.ApproveRequest,
|
|
99
|
+
params: { id, data },
|
|
100
|
+
}), api_1.ApproveRequestResponseStruct);
|
|
101
|
+
}
|
|
102
|
+
async rejectRequest(id) {
|
|
103
|
+
(0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
|
104
|
+
method: rpc_1.KeyringRpcMethod.RejectRequest,
|
|
105
|
+
params: { id },
|
|
106
|
+
}), api_1.RejectRequestResponseStruct);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.KeyringClient = KeyringClient;
|
|
110
|
+
_KeyringClient_sender = new WeakMap(), _KeyringClient_instances = new WeakSet(), _KeyringClient_send =
|
|
111
|
+
/**
|
|
112
|
+
* Send a request to the snap and return the response.
|
|
113
|
+
*
|
|
114
|
+
* @param partial - A partial JSON-RPC request (method and params).
|
|
115
|
+
* @returns A promise that resolves to the response to the request.
|
|
116
|
+
*/
|
|
117
|
+
async function _KeyringClient_send(partial) {
|
|
118
|
+
return __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
|
|
119
|
+
jsonrpc: '2.0',
|
|
120
|
+
id: (0, uuid_1.v4)(),
|
|
121
|
+
...partial,
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=KeyringClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":"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","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n CaipAssetType,\n Balance,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountBalancesResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { strictMask } from './superstruct';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param partial - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n async #send(partial: Omit<JsonRpcRequest, 'jsonrpc' | 'id'>): Promise<Json> {\n return this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n ...partial,\n });\n }\n\n async listAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccounts,\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async getAccountBalances(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.CreateAccount,\n params: { options },\n }),\n CreateAccountResponseStruct,\n );\n }\n\n async filterAccountChains(id: string, chains: string[]): Promise<string[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.FilterAccountChains,\n params: { id, chains },\n }),\n FilterAccountChainsResponseStruct,\n );\n }\n\n async updateAccount(account: KeyringAccount): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.UpdateAccount,\n params: { account },\n }),\n UpdateAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async exportAccount(id: string): Promise<KeyringAccountData> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ExportAccount,\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListRequests,\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetRequest,\n params: { id },\n }),\n GetRequestResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n async approveRequest(\n id: string,\n data: Record<string, Json> = {},\n ): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.ApproveRequest,\n params: { id, data },\n }),\n ApproveRequestResponseStruct,\n );\n }\n\n async rejectRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.RejectRequest,\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MetaMaskInpageProvider } from '@metamask/providers';
|
|
2
|
+
import type { Json } from '@metamask/utils';
|
|
3
|
+
import type { JsonRpcRequest } from './JsonRpcRequest';
|
|
4
|
+
import type { Sender } from './KeyringClient';
|
|
5
|
+
import { KeyringClient } from './KeyringClient';
|
|
6
|
+
/**
|
|
7
|
+
* Implementation of the `Sender` interface that can be used to send requests
|
|
8
|
+
* to a snap through the snap JSON-RPC API.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SnapRpcSender implements Sender {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of `SnapRpcSender`.
|
|
14
|
+
*
|
|
15
|
+
* @param origin - The caller's origin.
|
|
16
|
+
* @param provider - The `MetaMaskInpageProvider` instance to use.
|
|
17
|
+
*/
|
|
18
|
+
constructor(origin: string, provider: MetaMaskInpageProvider);
|
|
19
|
+
/**
|
|
20
|
+
* Send a request to the snap and return the response.
|
|
21
|
+
*
|
|
22
|
+
* @param request - The JSON-RPC request to send to the snap.
|
|
23
|
+
* @returns A promise that resolves to the response of the request.
|
|
24
|
+
*/
|
|
25
|
+
send(request: JsonRpcRequest): Promise<Json>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A `KeyringClient` that allows the communication with a snap through the snap
|
|
29
|
+
* JSON-RPC API.
|
|
30
|
+
*/
|
|
31
|
+
export declare class KeyringSnapRpcClient extends KeyringClient {
|
|
32
|
+
/**
|
|
33
|
+
* Create a new instance of `KeyringSnapRpcClient`.
|
|
34
|
+
*
|
|
35
|
+
* @param origin - Caller's origin.
|
|
36
|
+
* @param provider - The `MetaMaskInpageProvider` instance to use.
|
|
37
|
+
*/
|
|
38
|
+
constructor(origin: string, provider: MetaMaskInpageProvider);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=KeyringSnapRpcClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyringSnapRpcClient.d.ts","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,qBAAa,aAAc,YAAW,MAAM;;IAK1C;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;IAK5D;;;;;OAKG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CASnD;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;IACrD;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;CAG7D"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _SnapRpcSender_origin, _SnapRpcSender_provider;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.KeyringSnapRpcClient = exports.SnapRpcSender = void 0;
|
|
16
|
+
const KeyringClient_1 = require("./KeyringClient");
|
|
17
|
+
/**
|
|
18
|
+
* Implementation of the `Sender` interface that can be used to send requests
|
|
19
|
+
* to a snap through the snap JSON-RPC API.
|
|
20
|
+
*/
|
|
21
|
+
class SnapRpcSender {
|
|
22
|
+
/**
|
|
23
|
+
* Create a new instance of `SnapRpcSender`.
|
|
24
|
+
*
|
|
25
|
+
* @param origin - The caller's origin.
|
|
26
|
+
* @param provider - The `MetaMaskInpageProvider` instance to use.
|
|
27
|
+
*/
|
|
28
|
+
constructor(origin, provider) {
|
|
29
|
+
_SnapRpcSender_origin.set(this, void 0);
|
|
30
|
+
_SnapRpcSender_provider.set(this, void 0);
|
|
31
|
+
__classPrivateFieldSet(this, _SnapRpcSender_origin, origin, "f");
|
|
32
|
+
__classPrivateFieldSet(this, _SnapRpcSender_provider, provider, "f");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Send a request to the snap and return the response.
|
|
36
|
+
*
|
|
37
|
+
* @param request - The JSON-RPC request to send to the snap.
|
|
38
|
+
* @returns A promise that resolves to the response of the request.
|
|
39
|
+
*/
|
|
40
|
+
async send(request) {
|
|
41
|
+
return __classPrivateFieldGet(this, _SnapRpcSender_provider, "f").request({
|
|
42
|
+
method: 'wallet_invokeKeyring',
|
|
43
|
+
params: {
|
|
44
|
+
snapId: __classPrivateFieldGet(this, _SnapRpcSender_origin, "f"),
|
|
45
|
+
request,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.SnapRpcSender = SnapRpcSender;
|
|
51
|
+
_SnapRpcSender_origin = new WeakMap(), _SnapRpcSender_provider = new WeakMap();
|
|
52
|
+
/**
|
|
53
|
+
* A `KeyringClient` that allows the communication with a snap through the snap
|
|
54
|
+
* JSON-RPC API.
|
|
55
|
+
*/
|
|
56
|
+
class KeyringSnapRpcClient extends KeyringClient_1.KeyringClient {
|
|
57
|
+
/**
|
|
58
|
+
* Create a new instance of `KeyringSnapRpcClient`.
|
|
59
|
+
*
|
|
60
|
+
* @param origin - Caller's origin.
|
|
61
|
+
* @param provider - The `MetaMaskInpageProvider` instance to use.
|
|
62
|
+
*/
|
|
63
|
+
constructor(origin, provider) {
|
|
64
|
+
super(new SnapRpcSender(origin, provider));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.KeyringSnapRpcClient = KeyringSnapRpcClient;
|
|
68
|
+
//# sourceMappingURL=KeyringSnapRpcClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyringSnapRpcClient.js","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mDAAgD;AAEhD;;;GAGG;AACH,MAAa,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAV5D,wCAAgB;QAEhB,0CAAkC;QAShC,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2BAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,+BAAU,CAAC,OAAO,CAAC;YAC5B,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,MAAM,EAAE,uBAAA,IAAI,6BAAQ;gBACpB,OAAO;aACR;SACF,CAAkB,CAAC;IACtB,CAAC;CACF;AA/BD,sCA+BC;;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,6BAAa;IACrD;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAC1D,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAVD,oDAUC","sourcesContent":["import type { MetaMaskInpageProvider } from '@metamask/providers';\nimport type { Json } from '@metamask/utils';\n\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport type { Sender } from './KeyringClient';\nimport { KeyringClient } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through the snap JSON-RPC API.\n */\nexport class SnapRpcSender implements Sender {\n #origin: string;\n\n #provider: MetaMaskInpageProvider;\n\n /**\n * Create a new instance of `SnapRpcSender`.\n *\n * @param origin - The caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n this.#origin = origin;\n this.#provider = provider;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - The JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#provider.request({\n method: 'wallet_invokeKeyring',\n params: {\n snapId: this.#origin,\n request,\n },\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the snap\n * JSON-RPC API.\n */\nexport class KeyringSnapRpcClient extends KeyringClient {\n /**\n * Create a new instance of `KeyringSnapRpcClient`.\n *\n * @param origin - Caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n super(new SnapRpcSender(origin, provider));\n }\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Infer } from '@metamask/superstruct';
|
|
2
|
+
/**
|
|
3
|
+
* Supported Ethereum account types.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum EthAccountType {
|
|
6
|
+
Eoa = "eip155:eoa",
|
|
7
|
+
Erc4337 = "eip155:erc4337"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Supported Bitcoin account types.
|
|
11
|
+
*/
|
|
12
|
+
export declare enum BtcAccountType {
|
|
13
|
+
P2wpkh = "bip122:p2wpkh"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Supported account types.
|
|
17
|
+
*/
|
|
18
|
+
export declare type KeyringAccountType = `${EthAccountType.Eoa}` | `${EthAccountType.Erc4337}` | `${BtcAccountType.P2wpkh}`;
|
|
19
|
+
/**
|
|
20
|
+
* A struct which represents a Keyring account object. It is abstract enough to
|
|
21
|
+
* be used with any blockchain. Specific blockchain account types should extend
|
|
22
|
+
* this struct.
|
|
23
|
+
*
|
|
24
|
+
* See {@link KeyringAccount}.
|
|
25
|
+
*/
|
|
26
|
+
export declare const KeyringAccountStruct: import("@metamask/superstruct").Struct<{
|
|
27
|
+
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
|
|
28
|
+
id: string;
|
|
29
|
+
address: string;
|
|
30
|
+
options: Record<string, import("@metamask/utils").Json>;
|
|
31
|
+
methods: string[];
|
|
32
|
+
}, {
|
|
33
|
+
/**
|
|
34
|
+
* Account ID (UUIDv4).
|
|
35
|
+
*/
|
|
36
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
37
|
+
/**
|
|
38
|
+
* Account type.
|
|
39
|
+
*/
|
|
40
|
+
type: import("@metamask/superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
|
|
41
|
+
"eip155:eoa": "eip155:eoa";
|
|
42
|
+
"eip155:erc4337": "eip155:erc4337";
|
|
43
|
+
"bip122:p2wpkh": "bip122:p2wpkh";
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Account main address.
|
|
47
|
+
*/
|
|
48
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
|
49
|
+
/**
|
|
50
|
+
* Account options.
|
|
51
|
+
*/
|
|
52
|
+
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
|
53
|
+
/**
|
|
54
|
+
* Account supported methods.
|
|
55
|
+
*/
|
|
56
|
+
methods: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Keyring Account type represents an account and its properties from the
|
|
60
|
+
* point of view of the keyring.
|
|
61
|
+
*/
|
|
62
|
+
export declare type KeyringAccount = Infer<typeof KeyringAccountStruct>;
|
|
63
|
+
//# sourceMappingURL=account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/api/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAOnD;;GAEG;AACH,oBAAY,cAAc;IACxB,GAAG,eAAe;IAClB,OAAO,mBAAmB;CAC3B;AAED;;GAEG;AACH,oBAAY,cAAc;IACxB,MAAM,kBAAkB;CACzB;AAED;;GAEG;AACH,oBAAY,kBAAkB,GAC1B,GAAG,cAAc,CAAC,GAAG,EAAE,GACvB,GAAG,cAAc,CAAC,OAAO,EAAE,GAC3B,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC;AAE/B;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB;;;;;;;IAC/B;;OAEG;;IAGH;;OAEG;;;;;;IAOH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEH,CAAC;AAEH;;;GAGG;AACH,oBAAY,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyringAccountStruct = exports.BtcAccountType = exports.EthAccountType = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
const superstruct_2 = require("../superstruct");
|
|
7
|
+
const utils_2 = require("../utils");
|
|
8
|
+
/**
|
|
9
|
+
* Supported Ethereum account types.
|
|
10
|
+
*/
|
|
11
|
+
var EthAccountType;
|
|
12
|
+
(function (EthAccountType) {
|
|
13
|
+
EthAccountType["Eoa"] = "eip155:eoa";
|
|
14
|
+
EthAccountType["Erc4337"] = "eip155:erc4337";
|
|
15
|
+
})(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Supported Bitcoin account types.
|
|
18
|
+
*/
|
|
19
|
+
var BtcAccountType;
|
|
20
|
+
(function (BtcAccountType) {
|
|
21
|
+
BtcAccountType["P2wpkh"] = "bip122:p2wpkh";
|
|
22
|
+
})(BtcAccountType = exports.BtcAccountType || (exports.BtcAccountType = {}));
|
|
23
|
+
/**
|
|
24
|
+
* A struct which represents a Keyring account object. It is abstract enough to
|
|
25
|
+
* be used with any blockchain. Specific blockchain account types should extend
|
|
26
|
+
* this struct.
|
|
27
|
+
*
|
|
28
|
+
* See {@link KeyringAccount}.
|
|
29
|
+
*/
|
|
30
|
+
exports.KeyringAccountStruct = (0, superstruct_2.object)({
|
|
31
|
+
/**
|
|
32
|
+
* Account ID (UUIDv4).
|
|
33
|
+
*/
|
|
34
|
+
id: utils_2.UuidStruct,
|
|
35
|
+
/**
|
|
36
|
+
* Account type.
|
|
37
|
+
*/
|
|
38
|
+
type: (0, superstruct_1.enums)([
|
|
39
|
+
`${EthAccountType.Eoa}`,
|
|
40
|
+
`${EthAccountType.Erc4337}`,
|
|
41
|
+
`${BtcAccountType.P2wpkh}`,
|
|
42
|
+
]),
|
|
43
|
+
/**
|
|
44
|
+
* Account main address.
|
|
45
|
+
*/
|
|
46
|
+
address: (0, superstruct_1.string)(),
|
|
47
|
+
/**
|
|
48
|
+
* Account options.
|
|
49
|
+
*/
|
|
50
|
+
options: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
|
|
51
|
+
/**
|
|
52
|
+
* Account supported methods.
|
|
53
|
+
*/
|
|
54
|
+
methods: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/api/account.ts"],"names":[],"mappings":";;;AACA,uDAAqE;AACrE,2CAA6C;AAE7C,gDAAwC;AACxC,oCAAsC;AAEtC;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAED;;GAEG;AACH,IAAY,cAEX;AAFD,WAAY,cAAc;IACxB,0CAAwB,CAAA;AAC1B,CAAC,EAFW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAEzB;AAUD;;;;;;GAMG;AACU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC;QACV,GAAG,cAAc,CAAC,GAAG,EAAE;QACvB,GAAG,cAAc,CAAC,OAAO,EAAE;QAC3B,GAAG,cAAc,CAAC,MAAM,EAAE;KAC3B,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,GAAE;IAEjB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;IAErC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC;CACzB,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { array, enums, record, string } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { object } from '../superstruct';\nimport { UuidStruct } from '../utils';\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Erc4337 = 'eip155:erc4337',\n}\n\n/**\n * Supported Bitcoin account types.\n */\nexport enum BtcAccountType {\n P2wpkh = 'bip122:p2wpkh',\n}\n\n/**\n * Supported account types.\n */\nexport type KeyringAccountType =\n | `${EthAccountType.Eoa}`\n | `${EthAccountType.Erc4337}`\n | `${BtcAccountType.P2wpkh}`;\n\n/**\n * A struct which represents a Keyring account object. It is abstract enough to\n * be used with any blockchain. Specific blockchain account types should extend\n * this struct.\n *\n * See {@link KeyringAccount}.\n */\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account type.\n */\n type: enums([\n `${EthAccountType.Eoa}`,\n `${EthAccountType.Erc4337}`,\n `${BtcAccountType.P2wpkh}`,\n ]),\n\n /**\n * Account main address.\n */\n address: string(),\n\n /**\n * Account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(string()),\n});\n\n/**\n * Keyring Account type represents an account and its properties from the\n * point of view of the keyring.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Infer } from '@metamask/superstruct';
|
|
2
|
+
export declare const BalanceStruct: import("@metamask/superstruct").Struct<{
|
|
3
|
+
amount: string;
|
|
4
|
+
unit: string;
|
|
5
|
+
}, {
|
|
6
|
+
amount: import("@metamask/superstruct").Struct<string, null>;
|
|
7
|
+
unit: import("@metamask/superstruct").Struct<string, null>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare type Balance = Infer<typeof BalanceStruct>;
|
|
10
|
+
//# sourceMappingURL=balance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../src/api/balance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAMnD,eAAO,MAAM,aAAa;;;;;;EAGxB,CAAC;AAEH,oBAAY,OAAO,GAAG,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BalanceStruct = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const superstruct_2 = require("../superstruct");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
exports.BalanceStruct = (0, superstruct_2.object)({
|
|
8
|
+
amount: utils_1.StringNumberStruct,
|
|
9
|
+
unit: (0, superstruct_1.string)(),
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=balance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/api/balance.ts"],"names":[],"mappings":";;;AACA,uDAA+C;AAE/C,gDAAwC;AACxC,oCAA8C;AAEjC,QAAA,aAAa,GAAG,IAAA,oBAAM,EAAC;IAClC,MAAM,EAAE,0BAAkB;IAC1B,IAAI,EAAE,IAAA,oBAAM,GAAE;CACf,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { string } from '@metamask/superstruct';\n\nimport { object } from '../superstruct';\nimport { StringNumberStruct } from '../utils';\n\nexport const BalanceStruct = object({\n amount: StringNumberStruct,\n unit: string(),\n});\n\nexport type Balance = Infer<typeof BalanceStruct>;\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Infer } from '@metamask/superstruct';
|
|
2
|
+
/**
|
|
3
|
+
* A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CaipAssetTypeStruct: import("@metamask/superstruct").Struct<string, null>;
|
|
6
|
+
export declare type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;
|
|
7
|
+
/**
|
|
8
|
+
* A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CaipAssetIdStruct: import("@metamask/superstruct").Struct<string, null>;
|
|
11
|
+
export declare type CaipAssetId = Infer<typeof CaipAssetIdStruct>;
|
|
12
|
+
/**
|
|
13
|
+
* Check if the given value is a {@link CaipAssetType}.
|
|
14
|
+
*
|
|
15
|
+
* @param value - The value to check.
|
|
16
|
+
* @returns Whether the value is a {@link CaipAssetType}.
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* isCaipAssetType('eip155:1/slip44:60'); // true
|
|
20
|
+
* isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true
|
|
21
|
+
* isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function isCaipAssetType(value: unknown): value is CaipAssetType;
|
|
25
|
+
/**
|
|
26
|
+
* Check if the given value is a {@link CaipAssetId}.
|
|
27
|
+
*
|
|
28
|
+
* @param value - The value to check.
|
|
29
|
+
* @returns Whether the value is a {@link CaipAssetId}.
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* isCaipAssetType('eip155:1/slip44:60'); // false
|
|
33
|
+
* isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false
|
|
34
|
+
* isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function isCaipAssetId(value: unknown): value is CaipAssetId;
|
|
38
|
+
//# sourceMappingURL=caip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip.d.ts","sourceRoot":"","sources":["../../src/api/caip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAUvD;;GAEG;AACH,eAAO,MAAM,mBAAmB,sDAG/B,CAAC;AACF,oBAAY,aAAa,GAAG,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,iBAAiB,sDAG7B,CAAC;AACF,oBAAY,WAAW,GAAG,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE"}
|
package/dist/api/caip.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCaipAssetId = exports.isCaipAssetType = exports.CaipAssetIdStruct = exports.CaipAssetTypeStruct = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const superstruct_2 = require("../superstruct");
|
|
6
|
+
const CAIP_ASSET_TYPE_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;
|
|
7
|
+
const CAIP_ASSET_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;
|
|
8
|
+
/**
|
|
9
|
+
* A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
|
|
10
|
+
*/
|
|
11
|
+
exports.CaipAssetTypeStruct = (0, superstruct_2.definePattern)('CaipAssetType', CAIP_ASSET_TYPE_REGEX);
|
|
12
|
+
/**
|
|
13
|
+
* A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
|
|
14
|
+
*/
|
|
15
|
+
exports.CaipAssetIdStruct = (0, superstruct_2.definePattern)('CaipAssetId', CAIP_ASSET_ID_REGEX);
|
|
16
|
+
/**
|
|
17
|
+
* Check if the given value is a {@link CaipAssetType}.
|
|
18
|
+
*
|
|
19
|
+
* @param value - The value to check.
|
|
20
|
+
* @returns Whether the value is a {@link CaipAssetType}.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* isCaipAssetType('eip155:1/slip44:60'); // true
|
|
24
|
+
* isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true
|
|
25
|
+
* isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function isCaipAssetType(value) {
|
|
29
|
+
return (0, superstruct_1.is)(value, exports.CaipAssetTypeStruct);
|
|
30
|
+
}
|
|
31
|
+
exports.isCaipAssetType = isCaipAssetType;
|
|
32
|
+
/**
|
|
33
|
+
* Check if the given value is a {@link CaipAssetId}.
|
|
34
|
+
*
|
|
35
|
+
* @param value - The value to check.
|
|
36
|
+
* @returns Whether the value is a {@link CaipAssetId}.
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* isCaipAssetType('eip155:1/slip44:60'); // false
|
|
40
|
+
* isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false
|
|
41
|
+
* isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function isCaipAssetId(value) {
|
|
45
|
+
return (0, superstruct_1.is)(value, exports.CaipAssetIdStruct);
|
|
46
|
+
}
|
|
47
|
+
exports.isCaipAssetId = isCaipAssetId;
|
|
48
|
+
//# sourceMappingURL=caip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip.js","sourceRoot":"","sources":["../../src/api/caip.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AAEvD,gDAA+C;AAE/C,MAAM,qBAAqB,GACzB,2JAA2J,CAAC;AAE9J,MAAM,mBAAmB,GACvB,6LAA6L,CAAC;AAEhM;;GAEG;AACU,QAAA,mBAAmB,GAAG,IAAA,2BAAa,EAC9C,eAAe,EACf,qBAAqB,CACtB,CAAC;AAGF;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,2BAAa,EAC5C,aAAa,EACb,mBAAmB,CACpB,CAAC;AAGF;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,2BAAmB,CAAC,CAAC;AACxC,CAAC;AAFD,0CAEC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,yBAAiB,CAAC,CAAC;AACtC,CAAC;AAFD,sCAEC","sourcesContent":["import { is, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '../superstruct';\n\nconst CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nconst CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct = definePattern(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n);\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct = definePattern(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n);\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // true\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false\n * ```\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // false\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true\n * ```\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Infer } from '@metamask/superstruct';
|
|
2
|
+
export declare const KeyringAccountDataStruct: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
|
3
|
+
/**
|
|
4
|
+
* Response to a call to `exportAccount`.
|
|
5
|
+
*
|
|
6
|
+
* The exact response depends on the keyring implementation.
|
|
7
|
+
*/
|
|
8
|
+
export declare type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;
|
|
9
|
+
//# sourceMappingURL=export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/api/export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAInD,eAAO,MAAM,wBAAwB,8FAA+B,CAAC;AAErE;;;;GAIG;AACH,oBAAY,kBAAkB,GAAG,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyringAccountDataStruct = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
exports.KeyringAccountDataStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct);
|
|
7
|
+
//# sourceMappingURL=export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/api/export.ts"],"names":[],"mappings":";;;AACA,uDAAuD;AACvD,2CAA6C;AAEhC,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { record, string } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nexport const KeyringAccountDataStruct = record(string(), JsonStruct);\n\n/**\n * Response to a call to `exportAccount`.\n *\n * The exact response depends on the keyring implementation.\n */\nexport type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;\n"]}
|