@metamask/keyring-api 0.1.3 → 0.2.1
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/CHANGELOG.md +26 -1
- package/dist/JsonRpcRequest.d.ts +15 -0
- package/dist/JsonRpcRequest.js +18 -0
- package/dist/JsonRpcRequest.js.map +1 -0
- package/dist/{keyring-client.d.ts → KeyringClient.d.ts} +7 -6
- package/dist/{keyring-client.js → KeyringClient.js} +25 -20
- package/dist/KeyringClient.js.map +1 -0
- package/dist/{keyring-snap-controller-client.d.ts → KeyringSnapControllerClient.d.ts} +7 -1
- package/dist/{keyring-snap-controller-client.js → KeyringSnapControllerClient.js} +13 -7
- package/dist/KeyringSnapControllerClient.js.map +1 -0
- package/dist/{keyring-snap-rpc-client.d.ts → KeyringSnapRpcClient.d.ts} +4 -3
- package/dist/{keyring-snap-rpc-client.js → KeyringSnapRpcClient.js} +5 -7
- package/dist/KeyringSnapRpcClient.js.map +1 -0
- package/dist/{keyring-api.d.ts → api.d.ts} +72 -52
- package/dist/api.js +110 -0
- package/dist/api.js.map +1 -0
- package/dist/events.d.ts +10 -0
- package/dist/events.js +17 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/{keyring-internal-api.d.ts → internal/api.d.ts} +129 -260
- package/dist/internal/api.js +126 -0
- package/dist/internal/api.js.map +1 -0
- package/dist/internal/events.d.ts +162 -0
- package/dist/internal/events.js +58 -0
- package/dist/internal/events.js.map +1 -0
- package/dist/internal/index.d.ts +2 -0
- package/dist/internal/index.js +19 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/internal/types.d.ts +70 -0
- package/dist/internal/types.js +20 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/{keyring-rpc-dispatcher.d.ts → rpc-handler.d.ts} +17 -2
- package/dist/rpc-handler.js +141 -0
- package/dist/rpc-handler.js.map +1 -0
- package/dist/snap-utils.d.ts +11 -0
- package/dist/snap-utils.js +21 -0
- package/dist/snap-utils.js.map +1 -0
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js.map +1 -1
- package/package.json +14 -10
- package/dist/keyring-api.js +0 -81
- package/dist/keyring-api.js.map +0 -1
- package/dist/keyring-client.js.map +0 -1
- package/dist/keyring-internal-api.js +0 -154
- package/dist/keyring-internal-api.js.map +0 -1
- package/dist/keyring-rpc-dispatcher.js +0 -107
- package/dist/keyring-rpc-dispatcher.js.map +0 -1
- package/dist/keyring-snap-controller-client.js.map +0 -1
- package/dist/keyring-snap-rpc-client.js.map +0 -1
@@ -0,0 +1,141 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.handleKeyringRequest = exports.KeyringRpcMethod = exports.buildHandlersChain = exports.MethodNotSupportedError = void 0;
|
4
|
+
const superstruct_1 = require("superstruct");
|
5
|
+
const api_1 = require("./internal/api");
|
6
|
+
const JsonRpcRequest_1 = require("./JsonRpcRequest");
|
7
|
+
/**
|
8
|
+
* Error thrown when a keyring JSON-RPC method is not supported.
|
9
|
+
*/
|
10
|
+
class MethodNotSupportedError extends Error {
|
11
|
+
constructor(method) {
|
12
|
+
super(`Method not supported: ${method}`);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
exports.MethodNotSupportedError = MethodNotSupportedError;
|
16
|
+
/**
|
17
|
+
* Build a chain of handlers for a JSON-RPC request.
|
18
|
+
*
|
19
|
+
* If a handler throws a MethodNotSupportedError, the next handler in the chain
|
20
|
+
* is called. If all handlers throw a MethodNotSupportedError, the error is re-
|
21
|
+
* thrown.
|
22
|
+
*
|
23
|
+
* Any other error thrown by a handler is re-thrown.
|
24
|
+
*
|
25
|
+
* @param handlers - Handlers to chain.
|
26
|
+
* @returns A handler that chains the given handlers.
|
27
|
+
*/
|
28
|
+
function buildHandlersChain(...handlers) {
|
29
|
+
return async ({ origin, request }) => {
|
30
|
+
for (const handler of handlers) {
|
31
|
+
try {
|
32
|
+
return await handler({ origin, request });
|
33
|
+
}
|
34
|
+
catch (error) {
|
35
|
+
if (!(error instanceof MethodNotSupportedError)) {
|
36
|
+
throw error;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
// All handlers failed to handle the request.
|
41
|
+
throw new MethodNotSupportedError(request.method);
|
42
|
+
};
|
43
|
+
}
|
44
|
+
exports.buildHandlersChain = buildHandlersChain;
|
45
|
+
var KeyringRpcMethod;
|
46
|
+
(function (KeyringRpcMethod) {
|
47
|
+
KeyringRpcMethod["ListAccounts"] = "keyring_listAccounts";
|
48
|
+
KeyringRpcMethod["GetAccount"] = "keyring_getAccount";
|
49
|
+
KeyringRpcMethod["CreateAccount"] = "keyring_createAccount";
|
50
|
+
KeyringRpcMethod["FilterAccountChains"] = "keyring_filterAccountChains";
|
51
|
+
KeyringRpcMethod["UpdateAccount"] = "keyring_updateAccount";
|
52
|
+
KeyringRpcMethod["DeleteAccount"] = "keyring_deleteAccount";
|
53
|
+
KeyringRpcMethod["ExportAccount"] = "keyring_exportAccount";
|
54
|
+
KeyringRpcMethod["ListRequests"] = "keyring_listRequests";
|
55
|
+
KeyringRpcMethod["GetRequest"] = "keyring_getRequest";
|
56
|
+
KeyringRpcMethod["SubmitRequest"] = "keyring_submitRequest";
|
57
|
+
KeyringRpcMethod["ApproveRequest"] = "keyring_approveRequest";
|
58
|
+
KeyringRpcMethod["RejectRequest"] = "keyring_rejectRequest";
|
59
|
+
})(KeyringRpcMethod = exports.KeyringRpcMethod || (exports.KeyringRpcMethod = {}));
|
60
|
+
/**
|
61
|
+
* Handles a keyring JSON-RPC request.
|
62
|
+
*
|
63
|
+
* @param keyring - Keyring instance.
|
64
|
+
* @param request - Keyring JSON-RPC request.
|
65
|
+
* @returns A promise that resolves to the keyring response.
|
66
|
+
*/
|
67
|
+
async function handleKeyringRequest(keyring, request) {
|
68
|
+
// We first have to make sure that the request is a valid JSON-RPC request so
|
69
|
+
// we can check its method name.
|
70
|
+
(0, superstruct_1.assert)(request, JsonRpcRequest_1.JsonRpcRequestStruct);
|
71
|
+
switch (request.method) {
|
72
|
+
case KeyringRpcMethod.ListAccounts: {
|
73
|
+
(0, superstruct_1.assert)(request, api_1.ListAccountsRequestStruct);
|
74
|
+
return keyring.listAccounts();
|
75
|
+
}
|
76
|
+
case KeyringRpcMethod.GetAccount: {
|
77
|
+
(0, superstruct_1.assert)(request, api_1.GetAccountRequestStruct);
|
78
|
+
return keyring.getAccount(request.params.id);
|
79
|
+
}
|
80
|
+
case KeyringRpcMethod.CreateAccount: {
|
81
|
+
(0, superstruct_1.assert)(request, api_1.CreateAccountRequestStruct);
|
82
|
+
return keyring.createAccount(request.params.options);
|
83
|
+
}
|
84
|
+
case KeyringRpcMethod.FilterAccountChains: {
|
85
|
+
(0, superstruct_1.assert)(request, api_1.FilterAccountChainsStruct);
|
86
|
+
return keyring.filterAccountChains(request.params.id, request.params.chains);
|
87
|
+
}
|
88
|
+
case KeyringRpcMethod.UpdateAccount: {
|
89
|
+
(0, superstruct_1.assert)(request, api_1.UpdateAccountRequestStruct);
|
90
|
+
return keyring.updateAccount(request.params.account);
|
91
|
+
}
|
92
|
+
case KeyringRpcMethod.DeleteAccount: {
|
93
|
+
(0, superstruct_1.assert)(request, api_1.DeleteAccountRequestStruct);
|
94
|
+
return keyring.deleteAccount(request.params.id);
|
95
|
+
}
|
96
|
+
case KeyringRpcMethod.ExportAccount: {
|
97
|
+
if (keyring.exportAccount === undefined) {
|
98
|
+
throw new MethodNotSupportedError(request.method);
|
99
|
+
}
|
100
|
+
(0, superstruct_1.assert)(request, api_1.ExportAccountRequestStruct);
|
101
|
+
return keyring.exportAccount(request.params.id);
|
102
|
+
}
|
103
|
+
case KeyringRpcMethod.ListRequests: {
|
104
|
+
if (keyring.listRequests === undefined) {
|
105
|
+
throw new MethodNotSupportedError(request.method);
|
106
|
+
}
|
107
|
+
(0, superstruct_1.assert)(request, api_1.ListRequestsRequestStruct);
|
108
|
+
return keyring.listRequests();
|
109
|
+
}
|
110
|
+
case KeyringRpcMethod.GetRequest: {
|
111
|
+
if (keyring.getRequest === undefined) {
|
112
|
+
throw new MethodNotSupportedError(request.method);
|
113
|
+
}
|
114
|
+
(0, superstruct_1.assert)(request, api_1.GetRequestRequestStruct);
|
115
|
+
return keyring.getRequest(request.params.id);
|
116
|
+
}
|
117
|
+
case KeyringRpcMethod.SubmitRequest: {
|
118
|
+
(0, superstruct_1.assert)(request, api_1.SubmitRequestRequestStruct);
|
119
|
+
return keyring.submitRequest(request.params);
|
120
|
+
}
|
121
|
+
case KeyringRpcMethod.ApproveRequest: {
|
122
|
+
if (keyring.approveRequest === undefined) {
|
123
|
+
throw new MethodNotSupportedError(request.method);
|
124
|
+
}
|
125
|
+
(0, superstruct_1.assert)(request, api_1.ApproveRequestRequestStruct);
|
126
|
+
return keyring.approveRequest(request.params.id, request.params.data);
|
127
|
+
}
|
128
|
+
case KeyringRpcMethod.RejectRequest: {
|
129
|
+
if (keyring.rejectRequest === undefined) {
|
130
|
+
throw new MethodNotSupportedError(request.method);
|
131
|
+
}
|
132
|
+
(0, superstruct_1.assert)(request, api_1.RejectRequestRequestStruct);
|
133
|
+
return keyring.rejectRequest(request.params.id);
|
134
|
+
}
|
135
|
+
default: {
|
136
|
+
throw new MethodNotSupportedError(request.method);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
exports.handleKeyringRequest = handleKeyringRequest;
|
141
|
+
//# sourceMappingURL=rpc-handler.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AAEA,6CAAqC;AAGrC,wCAawB;AACxB,qDAA6E;AAE7E;;GAEG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc;QACxB,KAAK,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAJD,0DAIC;AAED;;;;;;;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MAAM,CAAC,CAAC;aACnD;YACD,IAAA,oBAAM,EAAC,OAAO,EAAE,gCAA0B,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACjD;QAED,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACnD;KACF;AACH,CAAC;AA3FD,oDA2FC","sourcesContent":["import type { OnRpcRequestHandler } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n} from './internal/api';\nimport { type JsonRpcRequest, JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Build a chain of handlers for a JSON-RPC request.\n *\n * If a handler throws a MethodNotSupportedError, the next handler in the chain\n * is called. If all handlers throw a MethodNotSupportedError, the error is re-\n * thrown.\n *\n * Any other error thrown by a handler is re-thrown.\n *\n * @param handlers - Handlers to chain.\n * @returns A handler that chains the given handlers.\n */\nexport function buildHandlersChain(\n ...handlers: OnRpcRequestHandler[]\n): OnRpcRequestHandler {\n return async ({ origin, request }) => {\n for (const handler of handlers) {\n try {\n return await handler({ origin, request });\n } catch (error) {\n if (!(error instanceof MethodNotSupportedError)) {\n throw error;\n }\n }\n }\n\n // All handlers failed to handle the request.\n throw new MethodNotSupportedError(request.method);\n };\n}\n\nexport enum KeyringRpcMethod {\n ListAccounts = 'keyring_listAccounts',\n GetAccount = 'keyring_getAccount',\n CreateAccount = 'keyring_createAccount',\n FilterAccountChains = 'keyring_filterAccountChains',\n UpdateAccount = 'keyring_updateAccount',\n DeleteAccount = 'keyring_deleteAccount',\n ExportAccount = 'keyring_exportAccount',\n ListRequests = 'keyring_listRequests',\n GetRequest = 'keyring_getRequest',\n SubmitRequest = 'keyring_submitRequest',\n ApproveRequest = 'keyring_approveRequest',\n RejectRequest = 'keyring_rejectRequest',\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case KeyringRpcMethod.ListAccounts: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case KeyringRpcMethod.GetAccount: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case KeyringRpcMethod.CreateAccount: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case KeyringRpcMethod.FilterAccountChains: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case KeyringRpcMethod.UpdateAccount: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case KeyringRpcMethod.DeleteAccount: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ExportAccount: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ListRequests: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case KeyringRpcMethod.GetRequest: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case KeyringRpcMethod.SubmitRequest: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case KeyringRpcMethod.ApproveRequest: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case KeyringRpcMethod.RejectRequest: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n"]}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { SnapsGlobalObject } from '@metamask/rpc-methods';
|
2
|
+
import type { Json } from '@metamask/utils';
|
3
|
+
import type { KeyringEvent } from './events';
|
4
|
+
/**
|
5
|
+
* Emit a keyring event from a snap.
|
6
|
+
*
|
7
|
+
* @param snap - The global snap object.
|
8
|
+
* @param event - The event name.
|
9
|
+
* @param data - The event data.
|
10
|
+
*/
|
11
|
+
export declare function emitSnapKeyringEvent(snap: SnapsGlobalObject, event: KeyringEvent, data: Record<string, Json>): Promise<void>;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.emitSnapKeyringEvent = void 0;
|
4
|
+
/**
|
5
|
+
* Emit a keyring event from a snap.
|
6
|
+
*
|
7
|
+
* @param snap - The global snap object.
|
8
|
+
* @param event - The event name.
|
9
|
+
* @param data - The event data.
|
10
|
+
*/
|
11
|
+
async function emitSnapKeyringEvent(snap, event, data) {
|
12
|
+
await snap.request({
|
13
|
+
method: 'snap_manageAccounts',
|
14
|
+
params: {
|
15
|
+
method: event,
|
16
|
+
params: { ...data },
|
17
|
+
},
|
18
|
+
});
|
19
|
+
}
|
20
|
+
exports.emitSnapKeyringEvent = emitSnapKeyringEvent;
|
21
|
+
//# sourceMappingURL=snap-utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"snap-utils.js","sourceRoot":"","sources":["../src/snap-utils.ts"],"names":[],"mappings":";;;AAKA;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,IAAuB,EACvB,KAAmB,EACnB,IAA0B;IAE1B,MAAM,IAAI,CAAC,OAAO,CAAC;QACjB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE;SACpB;KACF,CAAC,CAAC;AACL,CAAC;AAZD,oDAYC","sourcesContent":["import type { SnapsGlobalObject } from '@metamask/rpc-methods';\nimport type { Json } from '@metamask/utils';\n\nimport type { KeyringEvent } from './events';\n\n/**\n * Emit a keyring event from a snap.\n *\n * @param snap - The global snap object.\n * @param event - The event name.\n * @param data - The event data.\n */\nexport async function emitSnapKeyringEvent(\n snap: SnapsGlobalObject,\n event: KeyringEvent,\n data: Record<string, Json>,\n): Promise<void> {\n await snap.request({\n method: 'snap_manageAccounts',\n params: {\n method: event,\n params: { ...data },\n },\n });\n}\n"]}
|
package/dist/utils.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Struct } from 'superstruct';
|
1
|
+
import { type Struct } from 'superstruct';
|
2
2
|
/**
|
3
3
|
* UUIDv4 struct.
|
4
4
|
*/
|
@@ -11,7 +11,7 @@ export declare const UuidStruct: Struct<string, null>;
|
|
11
11
|
*
|
12
12
|
* See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>
|
13
13
|
*/
|
14
|
-
export declare type OmitUnion<
|
14
|
+
export declare type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
|
15
15
|
/**
|
16
16
|
* Assert that a value is valid according to a struct.
|
17
17
|
*
|
@@ -23,4 +23,4 @@ export declare type OmitUnion<T, K extends keyof any> = T extends any ? Omit<T,
|
|
23
23
|
* @param message - Error message to throw if the value is not valid.
|
24
24
|
* @returns The value if it is valid.
|
25
25
|
*/
|
26
|
-
export declare function strictMask<
|
26
|
+
export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
|
package/dist/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,6CAAmE;AAEnE;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,qBAAO,EAC/B,IAAA,oBAAM,GAAE,EACR,yEAAyE,CAC1E,CAAC;AAcF;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import { type Struct, assert, pattern, string } from 'superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = pattern(\n string(),\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask/keyring-api",
|
3
|
-
"version": "0.1
|
3
|
+
"version": "0.2.1",
|
4
4
|
"description": "MetaMask Keyring API",
|
5
5
|
"keywords": [
|
6
6
|
"metamask",
|
@@ -37,9 +37,10 @@
|
|
37
37
|
},
|
38
38
|
"dependencies": {
|
39
39
|
"@metamask/providers": "^11.0.0",
|
40
|
-
"@metamask/
|
41
|
-
"@metamask/snaps-
|
42
|
-
"@metamask/utils": "^
|
40
|
+
"@metamask/rpc-methods": "^0.38.1-flask.1",
|
41
|
+
"@metamask/snaps-controllers": "^0.38.2-flask.1",
|
42
|
+
"@metamask/snaps-utils": "^0.38.2-flask.1",
|
43
|
+
"@metamask/utils": "^8.0.0",
|
43
44
|
"@types/uuid": "^9.0.1",
|
44
45
|
"superstruct": "^1.0.3",
|
45
46
|
"uuid": "^9.0.0"
|
@@ -48,10 +49,10 @@
|
|
48
49
|
"@lavamoat/allow-scripts": "^2.3.1",
|
49
50
|
"@lavamoat/preinstall-always-fail": "^1.0.0",
|
50
51
|
"@metamask/auto-changelog": "^3.1.0",
|
51
|
-
"@metamask/eslint-config": "^
|
52
|
-
"@metamask/eslint-config-jest": "^
|
53
|
-
"@metamask/eslint-config-nodejs": "^
|
54
|
-
"@metamask/eslint-config-typescript": "^
|
52
|
+
"@metamask/eslint-config": "^12.1.0",
|
53
|
+
"@metamask/eslint-config-jest": "^12.1.0",
|
54
|
+
"@metamask/eslint-config-nodejs": "^12.1.0",
|
55
|
+
"@metamask/eslint-config-typescript": "^12.1.0",
|
55
56
|
"@types/jest": "^28.1.6",
|
56
57
|
"@types/node": "^16",
|
57
58
|
"@typescript-eslint/eslint-plugin": "^5.43.0",
|
@@ -62,8 +63,9 @@
|
|
62
63
|
"eslint-plugin-import": "^2.26.0",
|
63
64
|
"eslint-plugin-jest": "^27.1.5",
|
64
65
|
"eslint-plugin-jsdoc": "^39.6.2",
|
65
|
-
"eslint-plugin-
|
66
|
+
"eslint-plugin-n": "^16.0.1",
|
66
67
|
"eslint-plugin-prettier": "^4.2.1",
|
68
|
+
"eslint-plugin-promise": "^6.1.1",
|
67
69
|
"jest": "^28.1.3",
|
68
70
|
"jest-it-up": "^2.0.2",
|
69
71
|
"prettier": "^2.7.1",
|
@@ -90,7 +92,9 @@
|
|
90
92
|
"@metamask/snaps-utils>@metamask/base-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
|
91
93
|
"@metamask/snaps-utils>@metamask/base-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false,
|
92
94
|
"@metamask/snaps-utils>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
|
93
|
-
"@metamask/snaps-utils>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false
|
95
|
+
"@metamask/snaps-utils>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false,
|
96
|
+
"@metamask/rpc-methods>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
|
97
|
+
"@metamask/rpc-methods>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false
|
94
98
|
}
|
95
99
|
}
|
96
100
|
}
|
package/dist/keyring-api.js
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.SubmitRequestResponseStruct = exports.KeyringRequestStruct = exports.KeyringJsonRpcRequestStruct = exports.KeyringAccountStruct = void 0;
|
4
|
-
const utils_1 = require("@metamask/utils");
|
5
|
-
const superstruct_1 = require("superstruct");
|
6
|
-
const utils_2 = require("./utils");
|
7
|
-
exports.KeyringAccountStruct = (0, superstruct_1.object)({
|
8
|
-
/**
|
9
|
-
* Account ID (UUIDv4).
|
10
|
-
*/
|
11
|
-
id: utils_2.UuidStruct,
|
12
|
-
/**
|
13
|
-
* User-chosen account name.
|
14
|
-
*/
|
15
|
-
name: (0, superstruct_1.string)(),
|
16
|
-
/**
|
17
|
-
* Account address or next receive address (UTXO).
|
18
|
-
*/
|
19
|
-
address: (0, superstruct_1.string)(),
|
20
|
-
/**
|
21
|
-
* Keyring-dependent account options.
|
22
|
-
*/
|
23
|
-
options: (0, superstruct_1.nullable)((0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)),
|
24
|
-
/**
|
25
|
-
* Account supported methods.
|
26
|
-
*/
|
27
|
-
supportedMethods: (0, superstruct_1.array)((0, superstruct_1.enums)([
|
28
|
-
'personal_sign',
|
29
|
-
'eth_sendTransaction',
|
30
|
-
'eth_sign',
|
31
|
-
'eth_signTransaction',
|
32
|
-
'eth_signTypedData',
|
33
|
-
'eth_signTypedData_v1',
|
34
|
-
'eth_signTypedData_v2',
|
35
|
-
'eth_signTypedData_v3',
|
36
|
-
'eth_signTypedData_v4',
|
37
|
-
])),
|
38
|
-
/**
|
39
|
-
* Account type.
|
40
|
-
*/
|
41
|
-
type: (0, superstruct_1.enums)(['eip155:eoa', 'eip155:erc4337']),
|
42
|
-
});
|
43
|
-
exports.KeyringJsonRpcRequestStruct = (0, superstruct_1.union)([
|
44
|
-
(0, superstruct_1.object)({
|
45
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
46
|
-
id: (0, superstruct_1.string)(),
|
47
|
-
method: (0, superstruct_1.string)(),
|
48
|
-
}),
|
49
|
-
(0, superstruct_1.object)({
|
50
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
51
|
-
id: (0, superstruct_1.string)(),
|
52
|
-
method: (0, superstruct_1.string)(),
|
53
|
-
params: (0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)]),
|
54
|
-
}),
|
55
|
-
]);
|
56
|
-
exports.KeyringRequestStruct = (0, superstruct_1.object)({
|
57
|
-
/**
|
58
|
-
* Account ID (UUIDv4).
|
59
|
-
*/
|
60
|
-
account: utils_2.UuidStruct,
|
61
|
-
/**
|
62
|
-
* Request's scope (CAIP-2 chain ID).
|
63
|
-
*/
|
64
|
-
scope: (0, superstruct_1.string)(),
|
65
|
-
/**
|
66
|
-
* JSON-RPC request sent by the client application.
|
67
|
-
*
|
68
|
-
* Note: The request ID must be a string.
|
69
|
-
*/
|
70
|
-
request: exports.KeyringJsonRpcRequestStruct,
|
71
|
-
});
|
72
|
-
exports.SubmitRequestResponseStruct = (0, superstruct_1.union)([
|
73
|
-
(0, superstruct_1.object)({
|
74
|
-
pending: (0, superstruct_1.literal)(true),
|
75
|
-
}),
|
76
|
-
(0, superstruct_1.object)({
|
77
|
-
pending: (0, superstruct_1.literal)(false),
|
78
|
-
result: (0, superstruct_1.nullable)(utils_1.JsonStruct),
|
79
|
-
}),
|
80
|
-
]);
|
81
|
-
//# sourceMappingURL=keyring-api.js.map
|
package/dist/keyring-api.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"keyring-api.js","sourceRoot":"","sources":["../src/keyring-api.ts"],"names":[],"mappings":";;;AAAA,2CAAmD;AACnD,6CAUqB;AAErB,mCAAqC;AAExB,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,IAAI,EAAE,IAAA,oBAAM,GAAE;IAEd;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,GAAE;IAEjB;;OAEG;IACH,OAAO,EAAE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AC,IAAI,CAAC;KACvB,CAAC;IACF,IAAA,oBAAM,EAAC;QACL,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QACvB,MAAM,EAAE,IAAA,sBAAQ,EAAC,kBAAU,CAAC;KAC7B,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { Json, JsonStruct } from '@metamask/utils';\nimport {\n literal,\n union,\n nullable,\n object,\n string,\n enums,\n Infer,\n record,\n array,\n} from 'superstruct';\n\nimport { UuidStruct } from './utils';\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * User-chosen account name.\n */\n name: string(),\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: nullable(record(string(), JsonStruct)),\n\n /**\n * Account supported methods.\n */\n supportedMethods: array(\n enums([\n 'personal_sign',\n 'eth_sendTransaction',\n 'eth_sign',\n 'eth_signTransaction',\n 'eth_signTypedData',\n 'eth_signTypedData_v1',\n 'eth_signTypedData_v2',\n 'eth_signTypedData_v3',\n 'eth_signTypedData_v4',\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums(['eip155:eoa', 'eip155:erc4337']),\n});\n\n/**\n * Account object.\n *\n * Represents an account with its properties and capabilities.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n\nexport const KeyringJsonRpcRequestStruct = union([\n object({\n jsonrpc: literal('2.0'),\n id: string(),\n method: string(),\n }),\n object({\n jsonrpc: literal('2.0'),\n id: string(),\n method: string(),\n params: union([array(JsonStruct), record(string(), JsonStruct)]),\n }),\n]);\n\n/**\n * JSON-RPC request type.\n *\n * Represents a JSON-RPC request sent by a dApp. The request ID must be a\n * string and the params field cannot be undefined.\n */\nexport type KeyringJsonRpcRequest = Infer<typeof KeyringJsonRpcRequestStruct>;\n\nexport const KeyringRequestStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * JSON-RPC request sent by the client application.\n *\n * Note: The request ID must be a string.\n */\n request: KeyringJsonRpcRequestStruct,\n});\n\n/**\n * Keyring request.\n *\n * Represents a request made to the keyring for account-related operations.\n */\nexport type KeyringRequest = Infer<typeof KeyringRequestStruct>;\n\nexport const SubmitRequestResponseStruct = union([\n object({\n pending: literal(true),\n }),\n object({\n pending: literal(false),\n result: nullable(JsonStruct),\n }),\n]);\n\n/**\n * Response returned when submitting a request to the Keyring.\n */\nexport type SubmitRequestResponse = Infer<typeof SubmitRequestResponseStruct>;\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with the given name, supported chains, and optional\n * account options.\n *\n * @param name - The name of the account.\n * @param options - Keyring-defined options for the account (optional).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(\n name: string,\n options?: Record<string, Json> | null,\n ): Promise<KeyringAccount>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<SubmitRequestResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param result - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest(id: string, result?: Json): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest(id: string): Promise<void>;\n};\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"keyring-client.js","sourceRoot":"","sources":["../src/keyring-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AAElC,+CAMuB;AACvB,iEAagC;AAChC,mCAAgD;AAMhD,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAP1B,wCAAgB;QAQd,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAkBD,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI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AAE,IAAA,SAAI,GAAE;QACV,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\nimport { v4 as uuid } from 'uuid';\n\nimport {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n SubmitRequestResponse,\n SubmitRequestResponseStruct,\n} from './keyring-api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n InternalRequest,\n InternalResponse,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './keyring-internal-api';\nimport { OmitUnion, strictMask } from './utils';\n\nexport type Sender = {\n send(request: InternalRequest): Promise<InternalResponse>;\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 - Partial internal request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n async #send(\n partial: OmitUnion<InternalRequest, 'jsonrpc' | 'id'>,\n ): Promise<InternalResponse> {\n return await 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: 'keyring_listAccounts',\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: 'keyring_getAccount',\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async createAccount(\n name: string,\n options: Record<string, Json> | null = null,\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: 'keyring_createAccount',\n params: { name, 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: 'keyring_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: 'keyring_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: 'keyring_deleteAccount',\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: 'keyring_listRequests',\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: 'keyring_getRequest',\n params: { id },\n }),\n GetRequestResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<SubmitRequestResponse> {\n return strictMask(\n await this.#send({\n method: 'keyring_submitRequest',\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n async approveRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: 'keyring_approveRequest',\n params: { id },\n }),\n ApproveRequestResponseStruct,\n );\n }\n\n async rejectRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: 'keyring_rejectRequest',\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
|
@@ -1,154 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.InternalResponseStruct = exports.InternalRequestStruct = exports.RejectRequestResponseStruct = exports.RejectRequestRequestStruct = exports.ApproveRequestResponseStruct = exports.ApproveRequestRequestStruct = exports.SubmitRequestRequestStruct = exports.GetRequestResponseStruct = exports.GetRequestRequestStruct = exports.ListRequestsResponseStruct = exports.ListRequestsRequestStruct = 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;
|
4
|
-
const utils_1 = require("@metamask/utils");
|
5
|
-
const superstruct_1 = require("superstruct");
|
6
|
-
const keyring_api_1 = require("./keyring-api");
|
7
|
-
const utils_2 = require("./utils");
|
8
|
-
// ----------------------------------------------------------------------------
|
9
|
-
// List accounts
|
10
|
-
exports.ListAccountsRequestStruct = (0, superstruct_1.object)({
|
11
|
-
id: utils_2.UuidStruct,
|
12
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
13
|
-
method: (0, superstruct_1.literal)('keyring_listAccounts'),
|
14
|
-
});
|
15
|
-
exports.ListAccountsResponseStruct = (0, superstruct_1.array)(keyring_api_1.KeyringAccountStruct);
|
16
|
-
// ----------------------------------------------------------------------------
|
17
|
-
// Get account
|
18
|
-
exports.GetAccountRequestStruct = (0, superstruct_1.object)({
|
19
|
-
id: utils_2.UuidStruct,
|
20
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
21
|
-
method: (0, superstruct_1.literal)('keyring_getAccount'),
|
22
|
-
params: (0, superstruct_1.object)({
|
23
|
-
id: (0, superstruct_1.string)(),
|
24
|
-
}),
|
25
|
-
});
|
26
|
-
exports.GetAccountResponseStruct = keyring_api_1.KeyringAccountStruct;
|
27
|
-
// ----------------------------------------------------------------------------
|
28
|
-
// Create account
|
29
|
-
exports.CreateAccountRequestStruct = (0, superstruct_1.object)({
|
30
|
-
id: utils_2.UuidStruct,
|
31
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
32
|
-
method: (0, superstruct_1.literal)('keyring_createAccount'),
|
33
|
-
params: (0, superstruct_1.object)({
|
34
|
-
name: (0, superstruct_1.string)(),
|
35
|
-
options: (0, superstruct_1.nullable)((0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)),
|
36
|
-
}),
|
37
|
-
});
|
38
|
-
exports.CreateAccountResponseStruct = keyring_api_1.KeyringAccountStruct;
|
39
|
-
// ----------------------------------------------------------------------------
|
40
|
-
// Filter account chains
|
41
|
-
exports.FilterAccountChainsStruct = (0, superstruct_1.object)({
|
42
|
-
id: utils_2.UuidStruct,
|
43
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
44
|
-
method: (0, superstruct_1.literal)('keyring_filterAccountChains'),
|
45
|
-
params: (0, superstruct_1.object)({
|
46
|
-
id: (0, superstruct_1.string)(),
|
47
|
-
chains: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
48
|
-
}),
|
49
|
-
});
|
50
|
-
exports.FilterAccountChainsResponseStruct = (0, superstruct_1.array)((0, superstruct_1.string)());
|
51
|
-
// ----------------------------------------------------------------------------
|
52
|
-
// Update account
|
53
|
-
exports.UpdateAccountRequestStruct = (0, superstruct_1.object)({
|
54
|
-
id: utils_2.UuidStruct,
|
55
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
56
|
-
method: (0, superstruct_1.literal)('keyring_updateAccount'),
|
57
|
-
params: (0, superstruct_1.object)({
|
58
|
-
account: keyring_api_1.KeyringAccountStruct,
|
59
|
-
}),
|
60
|
-
});
|
61
|
-
exports.UpdateAccountResponseStruct = (0, superstruct_1.nullable)((0, superstruct_1.never)());
|
62
|
-
// ----------------------------------------------------------------------------
|
63
|
-
// Delete account
|
64
|
-
exports.DeleteAccountRequestStruct = (0, superstruct_1.object)({
|
65
|
-
id: utils_2.UuidStruct,
|
66
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
67
|
-
method: (0, superstruct_1.literal)('keyring_deleteAccount'),
|
68
|
-
params: (0, superstruct_1.object)({
|
69
|
-
id: (0, superstruct_1.string)(),
|
70
|
-
}),
|
71
|
-
});
|
72
|
-
exports.DeleteAccountResponseStruct = (0, superstruct_1.nullable)((0, superstruct_1.never)());
|
73
|
-
// ----------------------------------------------------------------------------
|
74
|
-
// List requests
|
75
|
-
exports.ListRequestsRequestStruct = (0, superstruct_1.object)({
|
76
|
-
id: utils_2.UuidStruct,
|
77
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
78
|
-
method: (0, superstruct_1.literal)('keyring_listRequests'),
|
79
|
-
});
|
80
|
-
exports.ListRequestsResponseStruct = (0, superstruct_1.array)(keyring_api_1.KeyringRequestStruct);
|
81
|
-
// ----------------------------------------------------------------------------
|
82
|
-
// Get request
|
83
|
-
exports.GetRequestRequestStruct = (0, superstruct_1.object)({
|
84
|
-
id: utils_2.UuidStruct,
|
85
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
86
|
-
method: (0, superstruct_1.literal)('keyring_getRequest'),
|
87
|
-
params: (0, superstruct_1.object)({
|
88
|
-
id: (0, superstruct_1.string)(),
|
89
|
-
}),
|
90
|
-
});
|
91
|
-
exports.GetRequestResponseStruct = keyring_api_1.KeyringRequestStruct;
|
92
|
-
// ----------------------------------------------------------------------------
|
93
|
-
// Submit request
|
94
|
-
exports.SubmitRequestRequestStruct = (0, superstruct_1.object)({
|
95
|
-
id: utils_2.UuidStruct,
|
96
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
97
|
-
method: (0, superstruct_1.literal)('keyring_submitRequest'),
|
98
|
-
params: keyring_api_1.KeyringRequestStruct,
|
99
|
-
});
|
100
|
-
// The response type is already defined in the `keyring-api.ts` file since it
|
101
|
-
// is used by the `Keyring` interface.
|
102
|
-
// ----------------------------------------------------------------------------
|
103
|
-
// Approve request
|
104
|
-
exports.ApproveRequestRequestStruct = (0, superstruct_1.object)({
|
105
|
-
id: utils_2.UuidStruct,
|
106
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
107
|
-
method: (0, superstruct_1.literal)('keyring_approveRequest'),
|
108
|
-
params: (0, superstruct_1.object)({
|
109
|
-
id: (0, superstruct_1.string)(),
|
110
|
-
}),
|
111
|
-
});
|
112
|
-
exports.ApproveRequestResponseStruct = (0, superstruct_1.nullable)((0, superstruct_1.never)());
|
113
|
-
// ----------------------------------------------------------------------------
|
114
|
-
// Reject request
|
115
|
-
exports.RejectRequestRequestStruct = (0, superstruct_1.object)({
|
116
|
-
id: utils_2.UuidStruct,
|
117
|
-
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
118
|
-
method: (0, superstruct_1.literal)('keyring_rejectRequest'),
|
119
|
-
params: (0, superstruct_1.object)({
|
120
|
-
id: (0, superstruct_1.string)(),
|
121
|
-
}),
|
122
|
-
});
|
123
|
-
exports.RejectRequestResponseStruct = (0, superstruct_1.nullable)((0, superstruct_1.never)());
|
124
|
-
// ----------------------------------------------------------------------------
|
125
|
-
// Internal request
|
126
|
-
exports.InternalRequestStruct = (0, superstruct_1.union)([
|
127
|
-
exports.ListAccountsRequestStruct,
|
128
|
-
exports.GetAccountRequestStruct,
|
129
|
-
exports.CreateAccountRequestStruct,
|
130
|
-
exports.FilterAccountChainsStruct,
|
131
|
-
exports.UpdateAccountRequestStruct,
|
132
|
-
exports.DeleteAccountRequestStruct,
|
133
|
-
exports.ListRequestsRequestStruct,
|
134
|
-
exports.GetRequestRequestStruct,
|
135
|
-
exports.SubmitRequestRequestStruct,
|
136
|
-
exports.ApproveRequestRequestStruct,
|
137
|
-
exports.RejectRequestRequestStruct,
|
138
|
-
]);
|
139
|
-
// ----------------------------------------------------------------------------
|
140
|
-
// Internal response
|
141
|
-
exports.InternalResponseStruct = (0, superstruct_1.union)([
|
142
|
-
exports.ListAccountsResponseStruct,
|
143
|
-
exports.GetAccountResponseStruct,
|
144
|
-
exports.CreateAccountResponseStruct,
|
145
|
-
exports.FilterAccountChainsResponseStruct,
|
146
|
-
exports.UpdateAccountResponseStruct,
|
147
|
-
exports.DeleteAccountResponseStruct,
|
148
|
-
exports.ListRequestsResponseStruct,
|
149
|
-
exports.GetRequestResponseStruct,
|
150
|
-
keyring_api_1.SubmitRequestResponseStruct,
|
151
|
-
exports.ApproveRequestResponseStruct,
|
152
|
-
exports.RejectRequestResponseStruct,
|
153
|
-
]);
|
154
|
-
//# sourceMappingURL=keyring-internal-api.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"keyring-internal-api.js","sourceRoot":"","sources":["../src/keyring-internal-api.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,6CAUqB;AAErB,+CAIuB;AACvB,mCAAqC;AAErC,+EAA+E;AAC/E,gBAAgB;AAEH,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,EAAE,EAAE,kBAAU;IACd,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,MAAM,EAAE,IAAA,qBAAO,EAAC,sBAAsB,CAAC;CACxC,CAAC,CAAC;AAIU,QAAA,0BAA0B,GAAG,IAAA,mBAAK,EAAC,kCAAoB,CAAC,CAAC;AAItE,+EAA+E;AAC/E,cAAc;AAED,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IAC5C,EAAE,EAAE,kBAAU;IACd,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,MAAM,EAAE,IAAA,qBAAO,EAAC,oBAAoB,CAAC;IACrC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,EAAE,EAAE,IAAA,oBAAM,GAAE;KACb,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,wBAAwB,GAAG,kCAAoB,CAAC;AAI7D,+EAA+E;AAC/E,iBAAiB;AAEJ,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,EAAE,EAAE,kBAAU;IACd,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,MAAM,EAAE,IAAA,qBAAO,EAAC,uBAAuB,CAAC;IACxC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,OAAO,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,EAAC,IAAA,oBAAM,G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EAAE,IAAA,oBAAM,GAAE;KACb,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,4BAA4B,GAAG,IAAA,sBAAQ,EAAC,IAAA,mBAAK,GAAE,CAAC,CAAC;AAI9D,+EAA+E;AAC/E,iBAAiB;AAEJ,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,EAAE,EAAE,kBAAU;IACd,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,MAAM,EAAE,IAAA,qBAAO,EAAC,uBAAuB,CAAC;IACxC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,EAAE,EAAE,IAAA,oBAAM,GAAE;KACb,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,2BAA2B,GAAG,IAAA,sBAAQ,EAAC,IAAA,mBAAK,GAAE,CAAC,CAAC;AAI7D,+EAA+E;AAC/E,mBAAmB;AAEN,QAAA,qBAAqB,GAAG,IAAA,mBAAK,EAAC;IACzC,iCAAyB;IACzB,+BAAuB;IACvB,kCAA0B;IAC1B,iCAAyB;IACzB,kCAA0B;IAC1B,kCAA0B;IAC1B,iCAAyB;IACzB,+BAAuB;IACvB,kCAA0B;IAC1B,mCAA2B;IAC3B,kCAA0B;CAC3B,CAAC,CAAC;AAIH,+EAA+E;AAC/E,oBAAoB;AAEP,QAAA,sBAAsB,GAAG,IAAA,mBAAK,EAAC;IAC1C,kCAA0B;IAC1B,gCAAwB;IACxB,mCAA2B;IAC3B,yCAAiC;IACjC,mCAA2B;IAC3B,mCAA2B;IAC3B,kCAA0B;IAC1B,gCAAwB;IACxB,yCAA2B;IAC3B,oCAA4B;IAC5B,mCAA2B;CAC5B,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport {\n array,\n Infer,\n literal,\n never,\n nullable,\n object,\n record,\n string,\n union,\n} from 'superstruct';\n\nimport {\n KeyringAccountStruct,\n KeyringRequestStruct,\n SubmitRequestResponseStruct,\n} from './keyring-api';\nimport { UuidStruct } from './utils';\n\n// ----------------------------------------------------------------------------\n// List accounts\n\nexport const ListAccountsRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_listAccounts'),\n});\n\nexport type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;\n\nexport const ListAccountsResponseStruct = array(KeyringAccountStruct);\n\nexport type ListAccountsResponse = Infer<typeof ListAccountsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get account\n\nexport const GetAccountRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_getAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;\n\nexport const GetAccountResponseStruct = KeyringAccountStruct;\n\nexport type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Create account\n\nexport const CreateAccountRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_createAccount'),\n params: object({\n name: string(),\n options: nullable(record(string(), JsonStruct)),\n }),\n});\n\nexport type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;\n\nexport const CreateAccountResponseStruct = KeyringAccountStruct;\n\nexport type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Filter account chains\n\nexport const FilterAccountChainsStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_filterAccountChains'),\n params: object({\n id: string(),\n chains: array(string()),\n }),\n});\n\nexport type FilterAccountChainsRequest = Infer<\n typeof FilterAccountChainsStruct\n>;\n\nexport const FilterAccountChainsResponseStruct = array(string());\n\nexport type FilterAccountChainsResponse = Infer<\n typeof FilterAccountChainsResponseStruct\n>;\n\n// ----------------------------------------------------------------------------\n// Update account\n\nexport const UpdateAccountRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_updateAccount'),\n params: object({\n account: KeyringAccountStruct,\n }),\n});\n\nexport type UpdateAccountRequest = Infer<typeof UpdateAccountRequestStruct>;\n\nexport const UpdateAccountResponseStruct = nullable(never());\n\nexport type UpdateAccountResponse = Infer<typeof UpdateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Delete account\n\nexport const DeleteAccountRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_deleteAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type DeleteAccountRequest = Infer<typeof DeleteAccountRequestStruct>;\n\nexport const DeleteAccountResponseStruct = nullable(never());\n\nexport type DeleteAccountResponse = Infer<typeof DeleteAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// List requests\n\nexport const ListRequestsRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_listRequests'),\n});\n\nexport type ListRequestsRequest = Infer<typeof ListRequestsRequestStruct>;\n\nexport const ListRequestsResponseStruct = array(KeyringRequestStruct);\n\nexport type ListRequestsResponse = Infer<typeof ListRequestsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get request\n\nexport const GetRequestRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_getRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetRequestRequest = Infer<typeof GetRequestRequestStruct>;\n\nexport const GetRequestResponseStruct = KeyringRequestStruct;\n\nexport type GetRequestResponse = Infer<typeof GetRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Submit request\n\nexport const SubmitRequestRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_submitRequest'),\n params: KeyringRequestStruct,\n});\n\nexport type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;\n\n// The response type is already defined in the `keyring-api.ts` file since it\n// is used by the `Keyring` interface.\n\n// ----------------------------------------------------------------------------\n// Approve request\n\nexport const ApproveRequestRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_approveRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type ApproveRequestRequest = Infer<typeof ApproveRequestRequestStruct>;\n\nexport const ApproveRequestResponseStruct = nullable(never());\n\nexport type ApproveRequestResponse = Infer<typeof ApproveRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Reject request\n\nexport const RejectRequestRequestStruct = object({\n id: UuidStruct,\n jsonrpc: literal('2.0'),\n method: literal('keyring_rejectRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type RejectRequestRequest = Infer<typeof RejectRequestRequestStruct>;\n\nexport const RejectRequestResponseStruct = nullable(never());\n\nexport type RejectRequestResponse = Infer<typeof RejectRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Internal request\n\nexport const InternalRequestStruct = union([\n ListAccountsRequestStruct,\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n FilterAccountChainsStruct,\n UpdateAccountRequestStruct,\n DeleteAccountRequestStruct,\n ListRequestsRequestStruct,\n GetRequestRequestStruct,\n SubmitRequestRequestStruct,\n ApproveRequestRequestStruct,\n RejectRequestRequestStruct,\n]);\n\nexport type InternalRequest = Infer<typeof InternalRequestStruct>;\n\n// ----------------------------------------------------------------------------\n// Internal response\n\nexport const InternalResponseStruct = union([\n ListAccountsResponseStruct,\n GetAccountResponseStruct,\n CreateAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n UpdateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ListRequestsResponseStruct,\n GetRequestResponseStruct,\n SubmitRequestResponseStruct,\n ApproveRequestResponseStruct,\n RejectRequestResponseStruct,\n]);\n\nexport type InternalResponse = Infer<typeof InternalResponseStruct>;\n"]}
|