@metamask/keyring-api 0.2.2 → 0.2.4
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 +44 -25
- package/dist/JsonRpcRequest.d.ts +7 -6
- package/dist/JsonRpcRequest.js +5 -10
- package/dist/JsonRpcRequest.js.map +1 -1
- package/dist/KeyringClient.js +13 -12
- package/dist/KeyringClient.js.map +1 -1
- package/dist/api.d.ts +15 -13
- package/dist/api.js +13 -14
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/api.d.ts +31 -35
- package/dist/internal/events.d.ts +8 -12
- package/dist/internal/types.d.ts +9 -9
- package/dist/internal/types.js +7 -6
- package/dist/internal/types.js.map +1 -1
- package/dist/superstruct.d.ts +58 -0
- package/dist/superstruct.js +48 -0
- package/dist/superstruct.js.map +1 -0
- package/dist/superstruct.test-d.d.ts +1 -0
- package/dist/superstruct.test-d.js +17 -0
- package/dist/superstruct.test-d.js.map +1 -0
- package/package.json +10 -4
package/CHANGELOG.md
CHANGED
@@ -6,53 +6,70 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.2.4]
|
10
|
+
### Changed
|
11
|
+
- Fix linting and compatibility with older `tsc` ([#108](https://github.com/MetaMask/keyring-api/pull/108)).
|
12
|
+
|
13
|
+
## [0.2.3]
|
14
|
+
### Added
|
15
|
+
- Add redirection message to snap async response ([#102](https://github.com/MetaMask/keyring-api/pull/102)).
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
- Use `Omit` instead of `OmitUnion` ([#106](https://github.com/MetaMask/keyring-api/pull/106)).
|
19
|
+
- Update `KeyringResponse` comment ([#103](https://github.com/MetaMask/keyring-api/pull/103)).
|
20
|
+
- Use `KeyringRpcMethod` enum instead of string ([#105](https://github.com/MetaMask/keyring-api/pull/105)).
|
21
|
+
- Refactor tests to match superstruct examples ([#104](https://github.com/MetaMask/keyring-api/pull/104)).
|
22
|
+
- Add `exactOptional()` superstruct type ([#100](https://github.com/MetaMask/keyring-api/pull/100)).
|
23
|
+
- Bump @metamask/providers from 11.1.2 to 12.0.0 ([#99](https://github.com/MetaMask/keyring-api/pull/99)).
|
24
|
+
- Bump @metamask/providers from 11.1.1 to 11.1.2 ([#98](https://github.com/MetaMask/keyring-api/pull/98)).
|
25
|
+
|
9
26
|
## [0.2.2]
|
10
27
|
### Added
|
11
|
-
- Add architecture and EVM methods docs ([#86](https://github.com/MetaMask/keyring-api/pull/86))
|
12
|
-
- Add `lastSelected` and `lastActive` to metadata ([#92](https://github.com/MetaMask/keyring-api/pull/92))
|
28
|
+
- Add architecture and EVM methods docs ([#86](https://github.com/MetaMask/keyring-api/pull/86)).
|
29
|
+
- Add `lastSelected` and `lastActive` to metadata ([#92](https://github.com/MetaMask/keyring-api/pull/92)).
|
13
30
|
|
14
31
|
### Changed
|
15
|
-
- Make request `params` optional ([#96](https://github.com/MetaMask/keyring-api/pull/96))
|
16
|
-
- Remove `lastActive` field from internal account model ([#95](https://github.com/MetaMask/keyring-api/pull/95))
|
17
|
-
- Move request ID to outer request ([#94](https://github.com/MetaMask/keyring-api/pull/94))
|
32
|
+
- Make request `params` optional ([#96](https://github.com/MetaMask/keyring-api/pull/96)).
|
33
|
+
- Remove `lastActive` field from internal account model ([#95](https://github.com/MetaMask/keyring-api/pull/95)).
|
34
|
+
- Move request ID to outer request ([#94](https://github.com/MetaMask/keyring-api/pull/94)).
|
18
35
|
|
19
36
|
## [0.2.1]
|
20
37
|
### Changed
|
21
|
-
- Set `snap` object keys to be mandatory and move `name` to `metadata` ([#87](https://github.com/MetaMask/keyring-api/pull/87))
|
38
|
+
- Set `snap` object keys to be mandatory and move `name` to `metadata` ([#87](https://github.com/MetaMask/keyring-api/pull/87)).
|
22
39
|
|
23
40
|
## [0.2.0]
|
24
41
|
### Added
|
25
|
-
- Add `InternalAccount` type and create submodule `internal` ([#65](https://github.com/MetaMask/keyring-api/pull/65))
|
26
|
-
- Add keyring events and helper functions ([#74](https://github.com/MetaMask/keyring-api/pull/74))
|
27
|
-
- Add a `redirect` field to asynchronous request responses ([#75](https://github.com/MetaMask/keyring-api/pull/75))
|
28
|
-
- Add `exportAccount` method ([#60](https://github.com/MetaMask/keyring-api/pull/60))
|
29
|
-
- Add `getController` to client ([#43](https://github.com/MetaMask/keyring-api/pull/43))
|
42
|
+
- Add `InternalAccount` type and create submodule `internal` ([#65](https://github.com/MetaMask/keyring-api/pull/65)).
|
43
|
+
- Add keyring events and helper functions ([#74](https://github.com/MetaMask/keyring-api/pull/74)).
|
44
|
+
- Add a `redirect` field to asynchronous request responses ([#75](https://github.com/MetaMask/keyring-api/pull/75)).
|
45
|
+
- Add `exportAccount` method ([#60](https://github.com/MetaMask/keyring-api/pull/60)).
|
46
|
+
- Add `getController` to client ([#43](https://github.com/MetaMask/keyring-api/pull/43)).
|
30
47
|
|
31
48
|
### Changed
|
32
|
-
- Rename `erc4337` -> `eip4337` ([#42](https://github.com/MetaMask/keyring-api/pull/42))
|
33
|
-
- Make `options` a mandatory field of `KeyringAccount` ([#30](https://github.com/MetaMask/keyring-api/pull/30))
|
34
|
-
- Make `approveRequest` and `rejectRequest` optional ([#63](https://github.com/MetaMask/keyring-api/pull/63))
|
35
|
-
- Make `exportAccount`, `listRequests` and `getRequest` optional ([#73](https://github.com/MetaMask/keyring-api/pull/73))
|
36
|
-
- Export enums with account methods and types ([#66](https://github.com/MetaMask/keyring-api/pull/66))
|
37
|
-
- Make `approveRequest` accept a `result` argument ([#59](https://github.com/MetaMask/keyring-api/pull/59))
|
38
|
-
- Remove account name from `KeyringAccount` type ([#55](https://github.com/MetaMask/keyring-api/pull/55))
|
39
|
-
- Remove `eth_sendTransaction` method ([#50](https://github.com/MetaMask/keyring-api/pull/50))
|
40
|
-
- Rename `supportedMethods` to `methods` ([#35](https://github.com/MetaMask/keyring-api/pull/35))
|
49
|
+
- Rename `erc4337` -> `eip4337` ([#42](https://github.com/MetaMask/keyring-api/pull/42)).
|
50
|
+
- Make `options` a mandatory field of `KeyringAccount` ([#30](https://github.com/MetaMask/keyring-api/pull/30)).
|
51
|
+
- Make `approveRequest` and `rejectRequest` optional ([#63](https://github.com/MetaMask/keyring-api/pull/63)).
|
52
|
+
- Make `exportAccount`, `listRequests` and `getRequest` optional ([#73](https://github.com/MetaMask/keyring-api/pull/73)).
|
53
|
+
- Export enums with account methods and types ([#66](https://github.com/MetaMask/keyring-api/pull/66)).
|
54
|
+
- Make `approveRequest` accept a `result` argument ([#59](https://github.com/MetaMask/keyring-api/pull/59)).
|
55
|
+
- Remove account name from `KeyringAccount` type ([#55](https://github.com/MetaMask/keyring-api/pull/55)).
|
56
|
+
- Remove `eth_sendTransaction` method ([#50](https://github.com/MetaMask/keyring-api/pull/50)).
|
57
|
+
- Rename `supportedMethods` to `methods` ([#35](https://github.com/MetaMask/keyring-api/pull/35)).
|
41
58
|
|
42
59
|
## [0.1.3]
|
43
60
|
### Changed
|
44
|
-
- Downgrade snaps dependencies to `0.35.2-flask.1
|
61
|
+
- Downgrade snaps dependencies to `0.35.2-flask.1` ([#25](https://github.com/MetaMask/keyring-api/pull/25)).
|
45
62
|
|
46
63
|
## [0.1.2]
|
47
64
|
### Changed
|
48
|
-
- Update snaps dependencies
|
65
|
+
- Update snaps dependencies ([#21](https://github.com/MetaMask/keyring-api/pull/21)).
|
49
66
|
|
50
67
|
## [0.1.1]
|
51
68
|
### Added
|
52
|
-
- Validate snap responses for type correctness
|
69
|
+
- Validate snap responses for type correctness ([#15](https://github.com/MetaMask/keyring-api/pull/15)).
|
53
70
|
|
54
71
|
### Changed
|
55
|
-
- Rename RPC handling functions
|
72
|
+
- Rename RPC handling functions ([#16](https://github.com/MetaMask/keyring-api/pull/16)).
|
56
73
|
|
57
74
|
## [0.1.0] - 2023-06-20
|
58
75
|
### Added
|
@@ -62,7 +79,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
62
79
|
- SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
|
63
80
|
- Helper functions to create keyring handler in the snap.
|
64
81
|
|
65
|
-
[Unreleased]: https://github.com/MetaMask/keyring-api/compare/v0.2.
|
82
|
+
[Unreleased]: https://github.com/MetaMask/keyring-api/compare/v0.2.4...HEAD
|
83
|
+
[0.2.4]: https://github.com/MetaMask/keyring-api/compare/v0.2.3...v0.2.4
|
84
|
+
[0.2.3]: https://github.com/MetaMask/keyring-api/compare/v0.2.2...v0.2.3
|
66
85
|
[0.2.2]: https://github.com/MetaMask/keyring-api/compare/v0.2.1...v0.2.2
|
67
86
|
[0.2.1]: https://github.com/MetaMask/keyring-api/compare/v0.2.0...v0.2.1
|
68
87
|
[0.2.0]: https://github.com/MetaMask/keyring-api/compare/v0.1.3...v0.2.0
|
package/dist/JsonRpcRequest.d.ts
CHANGED
@@ -3,12 +3,13 @@ export declare const JsonRpcRequestStruct: import("superstruct").Struct<{
|
|
3
3
|
jsonrpc: "2.0";
|
4
4
|
id: string | number | null;
|
5
5
|
method: string;
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
7
|
+
}, {
|
8
|
+
jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
|
9
|
+
id: import("superstruct").Struct<string | number | null, null>;
|
10
|
+
method: import("superstruct").Struct<string, null>;
|
11
|
+
params: import("superstruct").Struct<import("./superstruct").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
|
12
|
+
}>;
|
12
13
|
/**
|
13
14
|
* JSON-RPC request type.
|
14
15
|
*/
|
package/dist/JsonRpcRequest.js
CHANGED
@@ -3,16 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JsonRpcRequestStruct = void 0;
|
4
4
|
const utils_1 = require("@metamask/utils");
|
5
5
|
const superstruct_1 = require("superstruct");
|
6
|
-
const
|
6
|
+
const superstruct_2 = require("./superstruct");
|
7
|
+
exports.JsonRpcRequestStruct = (0, superstruct_2.object)({
|
7
8
|
jsonrpc: (0, superstruct_1.literal)('2.0'),
|
8
|
-
id: (0, superstruct_1.
|
9
|
+
id: (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)(), (0, superstruct_1.literal)(null)]),
|
9
10
|
method: (0, superstruct_1.string)(),
|
10
|
-
|
11
|
-
|
12
|
-
params: (0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)]),
|
13
|
-
};
|
14
|
-
exports.JsonRpcRequestStruct = (0, superstruct_1.union)([
|
15
|
-
(0, superstruct_1.object)({ ...Common }),
|
16
|
-
(0, superstruct_1.object)({ ...Common, ...Params }),
|
17
|
-
]);
|
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
|
+
});
|
18
13
|
//# sourceMappingURL=JsonRpcRequest.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"JsonRpcRequest.js","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,
|
1
|
+
{"version":3,"file":"JsonRpcRequest.js","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAA4E;AAE5E,+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 { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, literal, number, record, string, union } from 'superstruct';\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"]}
|
package/dist/KeyringClient.js
CHANGED
@@ -16,6 +16,7 @@ exports.KeyringClient = void 0;
|
|
16
16
|
const superstruct_1 = require("superstruct");
|
17
17
|
const uuid_1 = require("uuid");
|
18
18
|
const api_1 = require("./internal/api");
|
19
|
+
const rpc_handler_1 = require("./rpc-handler");
|
19
20
|
const utils_1 = require("./utils");
|
20
21
|
class KeyringClient {
|
21
22
|
/**
|
@@ -30,71 +31,71 @@ class KeyringClient {
|
|
30
31
|
}
|
31
32
|
async listAccounts() {
|
32
33
|
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
33
|
-
method:
|
34
|
+
method: rpc_handler_1.KeyringRpcMethod.ListAccounts,
|
34
35
|
}), api_1.ListAccountsResponseStruct);
|
35
36
|
}
|
36
37
|
async getAccount(id) {
|
37
38
|
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
38
|
-
method:
|
39
|
+
method: rpc_handler_1.KeyringRpcMethod.GetAccount,
|
39
40
|
params: { id },
|
40
41
|
}), api_1.GetAccountResponseStruct);
|
41
42
|
}
|
42
43
|
async createAccount(options = {}) {
|
43
44
|
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
44
|
-
method:
|
45
|
+
method: rpc_handler_1.KeyringRpcMethod.CreateAccount,
|
45
46
|
params: { options },
|
46
47
|
}), api_1.CreateAccountResponseStruct);
|
47
48
|
}
|
48
49
|
async filterAccountChains(id, chains) {
|
49
50
|
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
50
|
-
method:
|
51
|
+
method: rpc_handler_1.KeyringRpcMethod.FilterAccountChains,
|
51
52
|
params: { id, chains },
|
52
53
|
}), api_1.FilterAccountChainsResponseStruct);
|
53
54
|
}
|
54
55
|
async updateAccount(account) {
|
55
56
|
(0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
56
|
-
method:
|
57
|
+
method: rpc_handler_1.KeyringRpcMethod.UpdateAccount,
|
57
58
|
params: { account },
|
58
59
|
}), api_1.UpdateAccountResponseStruct);
|
59
60
|
}
|
60
61
|
async deleteAccount(id) {
|
61
62
|
(0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
62
|
-
method:
|
63
|
+
method: rpc_handler_1.KeyringRpcMethod.DeleteAccount,
|
63
64
|
params: { id },
|
64
65
|
}), api_1.DeleteAccountResponseStruct);
|
65
66
|
}
|
66
67
|
async exportAccount(id) {
|
67
68
|
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
68
|
-
method:
|
69
|
+
method: rpc_handler_1.KeyringRpcMethod.ExportAccount,
|
69
70
|
params: { id },
|
70
71
|
}), api_1.ExportAccountResponseStruct);
|
71
72
|
}
|
72
73
|
async listRequests() {
|
73
74
|
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
74
|
-
method:
|
75
|
+
method: rpc_handler_1.KeyringRpcMethod.ListRequests,
|
75
76
|
}), api_1.ListRequestsResponseStruct);
|
76
77
|
}
|
77
78
|
async getRequest(id) {
|
78
79
|
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
79
|
-
method:
|
80
|
+
method: rpc_handler_1.KeyringRpcMethod.GetRequest,
|
80
81
|
params: { id },
|
81
82
|
}), api_1.GetRequestResponseStruct);
|
82
83
|
}
|
83
84
|
async submitRequest(request) {
|
84
85
|
return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
85
|
-
method:
|
86
|
+
method: rpc_handler_1.KeyringRpcMethod.SubmitRequest,
|
86
87
|
params: request,
|
87
88
|
}), api_1.SubmitRequestResponseStruct);
|
88
89
|
}
|
89
90
|
async approveRequest(id, data = {}) {
|
90
91
|
(0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
91
|
-
method:
|
92
|
+
method: rpc_handler_1.KeyringRpcMethod.ApproveRequest,
|
92
93
|
params: { id, data },
|
93
94
|
}), api_1.ApproveRequestResponseStruct);
|
94
95
|
}
|
95
96
|
async rejectRequest(id) {
|
96
97
|
(0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
|
97
|
-
method:
|
98
|
+
method: rpc_handler_1.KeyringRpcMethod.RejectRequest,
|
98
99
|
params: { id },
|
99
100
|
}), api_1.RejectRequestResponseStruct);
|
100
101
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AASlC,wCAawB;
|
1
|
+
{"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AASlC,wCAawB;AAExB,+CAAiD;AACjD,mCAAqC;AAMrC,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAP1B,wCAAgB;QAQd,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAgBD,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,YAAY;SACtC,CAAC,EACF,gCAA0B,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,UAAgC,EAAE;QAElC,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,OAAO,EAAE;SACpB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,EAAU,EAAE,MAAgB;QACpD,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,mBAAmB;YAC5C,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;SACvB,CAAC,EACF,uCAAiC,CAClC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,OAAO,EAAE;SACpB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,YAAY;SACtC,CAAC,EACF,gCAA0B,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,EAAU,EACV,OAA6B,EAAE;QAE/B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,cAAc;YACvC,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE;SACrB,CAAC,EACF,kCAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AApJD,sCAoJC;;AAxIC;;;;;GAKG;AACH,KAAK,8BAAO,OAA+C;IACzD,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;QACvB,OAAO,EAAE,KAAK;QACd,EAAE,EAAE,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 type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './internal/api';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { KeyringRpcMethod } from './rpc-handler';\nimport { strictMask } from './utils';\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 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"]}
|
package/dist/api.d.ts
CHANGED
@@ -20,11 +20,11 @@ export declare enum EthAccountType {
|
|
20
20
|
Eip4337 = "eip155:eip4337"
|
21
21
|
}
|
22
22
|
export declare const KeyringAccountStruct: import("superstruct").Struct<{
|
23
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
23
24
|
id: string;
|
24
25
|
address: string;
|
25
26
|
options: Record<string, Json>;
|
26
27
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
27
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
28
28
|
}, {
|
29
29
|
/**
|
30
30
|
* Account ID (UUIDv4).
|
@@ -70,9 +70,7 @@ export declare const KeyringRequestStruct: import("superstruct").Struct<{
|
|
70
70
|
account: string;
|
71
71
|
request: {
|
72
72
|
method: string;
|
73
|
-
|
74
|
-
method: string;
|
75
|
-
params: Json[] | Record<string, Json>;
|
73
|
+
params?: Json[] | Record<string, Json>;
|
76
74
|
};
|
77
75
|
}, {
|
78
76
|
/**
|
@@ -92,10 +90,11 @@ export declare const KeyringRequestStruct: import("superstruct").Struct<{
|
|
92
90
|
*/
|
93
91
|
request: import("superstruct").Struct<{
|
94
92
|
method: string;
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
93
|
+
params?: Json[] | Record<string, Json>;
|
94
|
+
}, {
|
95
|
+
method: import("superstruct").Struct<string, null>;
|
96
|
+
params: import("superstruct").Struct<import("./superstruct").ExactOptionalTag | Json[] | Record<string, Json>, null>;
|
97
|
+
}>;
|
99
98
|
}>;
|
100
99
|
/**
|
101
100
|
* Keyring request.
|
@@ -112,7 +111,10 @@ export declare const KeyringAccountDataStruct: import("superstruct").Struct<Reco
|
|
112
111
|
export declare type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;
|
113
112
|
export declare const KeyringResponseStruct: import("superstruct").Struct<{
|
114
113
|
pending: true;
|
115
|
-
redirect
|
114
|
+
redirect?: {
|
115
|
+
message?: string;
|
116
|
+
url?: string;
|
117
|
+
};
|
116
118
|
} | {
|
117
119
|
pending: false;
|
118
120
|
result: Json;
|
@@ -124,10 +126,10 @@ export declare const KeyringResponseStruct: import("superstruct").Struct<{
|
|
124
126
|
* request will be handled asynchronously. Otherwise, the response must contain
|
125
127
|
* the result of the request and `pending: false`.
|
126
128
|
*
|
127
|
-
* In the asynchronous case, the keyring can return a redirect URL
|
128
|
-
* to the user. The user can choose to follow the link or cancel
|
129
|
-
* The main use case for this is to redirect the user to
|
130
|
-
* to
|
129
|
+
* In the asynchronous case, the keyring can return a redirect URL and message
|
130
|
+
* to be shown to the user. The user can choose to follow the link or cancel
|
131
|
+
* the request. The main use case for this is to redirect the user to the snap
|
132
|
+
* dapp to review the request.
|
131
133
|
*/
|
132
134
|
export declare type KeyringResponse = Infer<typeof KeyringResponseStruct>;
|
133
135
|
/**
|
package/dist/api.js
CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.KeyringResponseStruct = exports.KeyringAccountDataStruct = exports.KeyringRequestStruct = exports.KeyringAccountStruct = exports.EthAccountType = exports.EthMethod = void 0;
|
4
4
|
const utils_1 = require("@metamask/utils");
|
5
5
|
const superstruct_1 = require("superstruct");
|
6
|
+
const superstruct_2 = require("./superstruct");
|
6
7
|
const utils_2 = require("./utils");
|
7
8
|
/**
|
8
9
|
* Supported Ethereum methods.
|
@@ -25,7 +26,7 @@ var EthAccountType;
|
|
25
26
|
EthAccountType["Eoa"] = "eip155:eoa";
|
26
27
|
EthAccountType["Eip4337"] = "eip155:eip4337";
|
27
28
|
})(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
|
28
|
-
exports.KeyringAccountStruct = (0,
|
29
|
+
exports.KeyringAccountStruct = (0, superstruct_2.object)({
|
29
30
|
/**
|
30
31
|
* Account ID (UUIDv4).
|
31
32
|
*/
|
@@ -55,7 +56,7 @@ exports.KeyringAccountStruct = (0, superstruct_1.object)({
|
|
55
56
|
*/
|
56
57
|
type: (0, superstruct_1.enums)([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),
|
57
58
|
});
|
58
|
-
exports.KeyringRequestStruct = (0,
|
59
|
+
exports.KeyringRequestStruct = (0, superstruct_2.object)({
|
59
60
|
/**
|
60
61
|
* Keyring request ID (UUIDv4).
|
61
62
|
*/
|
@@ -71,19 +72,14 @@ exports.KeyringRequestStruct = (0, superstruct_1.object)({
|
|
71
72
|
/**
|
72
73
|
* Inner request sent by the client application.
|
73
74
|
*/
|
74
|
-
request: (0,
|
75
|
-
(0, superstruct_1.
|
76
|
-
|
77
|
-
|
78
|
-
(0, superstruct_1.object)({
|
79
|
-
method: (0, superstruct_1.string)(),
|
80
|
-
params: (0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)]),
|
81
|
-
}),
|
82
|
-
]),
|
75
|
+
request: (0, superstruct_2.object)({
|
76
|
+
method: (0, superstruct_1.string)(),
|
77
|
+
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)])),
|
78
|
+
}),
|
83
79
|
});
|
84
80
|
exports.KeyringAccountDataStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct);
|
85
81
|
exports.KeyringResponseStruct = (0, superstruct_1.union)([
|
86
|
-
(0,
|
82
|
+
(0, superstruct_2.object)({
|
87
83
|
/**
|
88
84
|
* Pending flag.
|
89
85
|
*
|
@@ -99,9 +95,12 @@ exports.KeyringResponseStruct = (0, superstruct_1.union)([
|
|
99
95
|
* with a link to the redirect URL. The user can choose to follow the link
|
100
96
|
* or cancel the request.
|
101
97
|
*/
|
102
|
-
redirect: (0,
|
98
|
+
redirect: (0, superstruct_2.exactOptional)((0, superstruct_2.object)({
|
99
|
+
message: (0, superstruct_2.exactOptional)((0, superstruct_1.string)()),
|
100
|
+
url: (0, superstruct_2.exactOptional)((0, superstruct_1.string)()),
|
101
|
+
})),
|
103
102
|
}),
|
104
|
-
(0,
|
103
|
+
(0, superstruct_2.object)({
|
105
104
|
/**
|
106
105
|
* Pending flag.
|
107
106
|
*
|
package/dist/api.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAE7C,6CASqB;AAErB,mCAAqC;AAErC;;GAEG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,gDAAmC,CAAA;IACnC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;AAC1C,CAAC,EARW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAQpB;AAED;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAEY,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;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,EACZ,IAAA,mBAAK,EAAC;QACJ,GAAG,SAAS,CAAC,YAAY,EAAE;QAC3B,GAAG,SAAS,CAAC,IAAI,EAAE;QACnB,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,aAAa,EAAE;QAC5B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;KAC/B,CAAC,CACH;IAED;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC;CACpE,CAAC,CAAC;AASU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,KAAK,EAAE,IAAA,oBAAM,GAAE;IAEf;;OAEG;IACH,OAAO,EAAE,kBAAU;IAEnB;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC;QACb,IAAA,oBAAM,EAAC;YACL,MAAM,EAAE,IAAA,oBAAM,GAAE;SACjB,CAAC;QACF,IAAA,oBAAM,EAAC;YACL,MAAM,EAAE,IAAA,oBAAM,GAAE;YAChB,MAAM,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC;SACjE,CAAC;KACH,CAAC;CACH,CAAC,CAAC;AASU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC;AASxD,QAAA,qBAAqB,GAAG,IAAA,mBAAK,EAAC;IACzC,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC;QAEtB;;;;;;WAMG;QACH,QAAQ,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;KAC7B,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n enums,\n literal,\n object,\n record,\n string,\n union,\n nullable,\n} from 'superstruct';\n\nimport { UuidStruct } from './utils';\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedData = 'eth_signTypedData',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Eip4337 = 'eip155:eip4337',\n}\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedData}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),\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 KeyringRequestStruct = object({\n /**\n * Keyring request ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Inner request sent by the client application.\n */\n request: union([\n object({\n method: string(),\n }),\n object({\n method: string(),\n params: union([array(JsonStruct), record(string(), JsonStruct)]),\n }),\n ]),\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 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\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: nullable(string()),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL to be shown\n * to the user. The user can choose to follow the link or cancel the request.\n * The main use case for this is to redirect the user to a third-party service\n * to approve the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\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 optional, keyring-defined, account options.\n *\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(options?: Record<string, Json>): 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 * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\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<KeyringResponse>;\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 data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, 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
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAE7C,6CAA2E;AAE3E,+CAAsD;AACtD,mCAAqC;AAErC;;GAEG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,gDAAmC,CAAA;IACnC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;AAC1C,CAAC,EARW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAQpB;AAED;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAEY,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;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,EACZ,IAAA,mBAAK,EAAC;QACJ,GAAG,SAAS,CAAC,YAAY,EAAE;QAC3B,GAAG,SAAS,CAAC,IAAI,EAAE;QACnB,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,aAAa,EAAE;QAC5B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;KAC/B,CAAC,CACH;IAED;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC;CACpE,CAAC,CAAC;AASU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,KAAK,EAAE,IAAA,oBAAM,GAAE;IAEf;;OAEG;IACH,OAAO,EAAE,kBAAU;IAEnB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC;QACd,MAAM,EAAE,IAAA,oBAAM,GAAE;QAChB,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;KACF,CAAC;CACH,CAAC,CAAC;AASU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC;AASxD,QAAA,qBAAqB,GAAG,IAAA,mBAAK,EAAC;IACzC,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC;QAEtB;;;;;;WAMG;QACH,QAAQ,EAAE,IAAA,2BAAa,EACrB,IAAA,oBAAM,EAAC;YACL,OAAO,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;YAChC,GAAG,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;SAC7B,CAAC,CACH;KACF,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, enums, literal, record, string, union } from 'superstruct';\n\nimport { exactOptional, object } from './superstruct';\nimport { UuidStruct } from './utils';\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedData = 'eth_signTypedData',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Eip4337 = 'eip155:eip4337',\n}\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedData}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),\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 KeyringRequestStruct = object({\n /**\n * Keyring request ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Inner request sent by the client application.\n */\n request: object({\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n }),\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 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\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: exactOptional(\n object({\n message: exactOptional(string()),\n url: exactOptional(string()),\n }),\n ),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL and message\n * to be shown to the user. The user can choose to follow the link or cancel\n * the request. The main use case for this is to redirect the user to the snap\n * dapp to review the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\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 optional, keyring-defined, account options.\n *\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(options?: Record<string, Json>): 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 * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\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<KeyringResponse>;\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 data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, 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"]}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -20,4 +20,6 @@ __exportStar(require("./rpc-handler"), exports);
|
|
20
20
|
__exportStar(require("./KeyringSnapControllerClient"), exports);
|
21
21
|
__exportStar(require("./KeyringSnapRpcClient"), exports);
|
22
22
|
__exportStar(require("./internal"), exports);
|
23
|
+
__exportStar(require("./snap-utils"), exports);
|
24
|
+
__exportStar(require("./superstruct"), exports);
|
23
25
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,kDAAgC;AAChC,gDAA8B;AAC9B,gEAA8C;AAC9C,yDAAuC;AACvC,6CAA2B","sourcesContent":["export * from './api';\nexport * from './KeyringClient';\nexport * from './rpc-handler';\nexport * from './KeyringSnapControllerClient';\nexport * from './KeyringSnapRpcClient';\nexport * from './internal';\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,kDAAgC;AAChC,gDAA8B;AAC9B,gEAA8C;AAC9C,yDAAuC;AACvC,6CAA2B;AAC3B,+CAA6B;AAC7B,gDAA8B","sourcesContent":["export * from './api';\nexport * from './KeyringClient';\nexport * from './rpc-handler';\nexport * from './KeyringSnapControllerClient';\nexport * from './KeyringSnapRpcClient';\nexport * from './internal';\nexport * from './snap-utils';\nexport * from './superstruct';\n"]}
|
package/dist/internal/api.d.ts
CHANGED
@@ -10,17 +10,17 @@ export declare const ListAccountsRequestStruct: import("superstruct").Struct<{
|
|
10
10
|
}>;
|
11
11
|
export declare type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;
|
12
12
|
export declare const ListAccountsResponseStruct: import("superstruct").Struct<{
|
13
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
13
14
|
id: string;
|
14
15
|
address: string;
|
15
16
|
options: Record<string, import("@metamask/utils").Json>;
|
16
17
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
17
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
18
18
|
}[], import("superstruct").Struct<{
|
19
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
19
20
|
id: string;
|
20
21
|
address: string;
|
21
22
|
options: Record<string, import("@metamask/utils").Json>;
|
22
23
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
23
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
24
24
|
}, {
|
25
25
|
id: import("superstruct").Struct<string, null>;
|
26
26
|
address: import("superstruct").Struct<string, null>;
|
@@ -59,11 +59,11 @@ export declare const GetAccountRequestStruct: import("superstruct").Struct<{
|
|
59
59
|
}>;
|
60
60
|
export declare type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;
|
61
61
|
export declare const GetAccountResponseStruct: import("superstruct").Struct<{
|
62
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
62
63
|
id: string;
|
63
64
|
address: string;
|
64
65
|
options: Record<string, import("@metamask/utils").Json>;
|
65
66
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
66
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
67
67
|
}, {
|
68
68
|
id: import("superstruct").Struct<string, null>;
|
69
69
|
address: import("superstruct").Struct<string, null>;
|
@@ -102,11 +102,11 @@ export declare const CreateAccountRequestStruct: import("superstruct").Struct<{
|
|
102
102
|
}>;
|
103
103
|
export declare type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;
|
104
104
|
export declare const CreateAccountResponseStruct: import("superstruct").Struct<{
|
105
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
105
106
|
id: string;
|
106
107
|
address: string;
|
107
108
|
options: Record<string, import("@metamask/utils").Json>;
|
108
109
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
109
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
110
110
|
}, {
|
111
111
|
id: import("superstruct").Struct<string, null>;
|
112
112
|
address: import("superstruct").Struct<string, null>;
|
@@ -155,30 +155,30 @@ export declare const UpdateAccountRequestStruct: import("superstruct").Struct<{
|
|
155
155
|
method: "keyring_updateAccount";
|
156
156
|
params: {
|
157
157
|
account: {
|
158
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
158
159
|
id: string;
|
159
160
|
address: string;
|
160
161
|
options: Record<string, import("@metamask/utils").Json>;
|
161
162
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
162
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
163
163
|
};
|
164
164
|
};
|
165
165
|
}, {
|
166
166
|
method: import("superstruct").Struct<"keyring_updateAccount", "keyring_updateAccount">;
|
167
167
|
params: import("superstruct").Struct<{
|
168
168
|
account: {
|
169
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
169
170
|
id: string;
|
170
171
|
address: string;
|
171
172
|
options: Record<string, import("@metamask/utils").Json>;
|
172
173
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
173
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
174
174
|
};
|
175
175
|
}, {
|
176
176
|
account: import("superstruct").Struct<{
|
177
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
177
178
|
id: string;
|
178
179
|
address: string;
|
179
180
|
options: Record<string, import("@metamask/utils").Json>;
|
180
181
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
181
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
182
182
|
}, {
|
183
183
|
id: import("superstruct").Struct<string, null>;
|
184
184
|
address: import("superstruct").Struct<string, null>;
|
@@ -260,9 +260,7 @@ export declare const ListRequestsResponseStruct: import("superstruct").Struct<{
|
|
260
260
|
account: string;
|
261
261
|
request: {
|
262
262
|
method: string;
|
263
|
-
|
264
|
-
method: string;
|
265
|
-
params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
263
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
266
264
|
};
|
267
265
|
}[], import("superstruct").Struct<{
|
268
266
|
id: string;
|
@@ -270,9 +268,7 @@ export declare const ListRequestsResponseStruct: import("superstruct").Struct<{
|
|
270
268
|
account: string;
|
271
269
|
request: {
|
272
270
|
method: string;
|
273
|
-
|
274
|
-
method: string;
|
275
|
-
params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
271
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
276
272
|
};
|
277
273
|
}, {
|
278
274
|
id: import("superstruct").Struct<string, null>;
|
@@ -280,10 +276,11 @@ export declare const ListRequestsResponseStruct: import("superstruct").Struct<{
|
|
280
276
|
account: import("superstruct").Struct<string, null>;
|
281
277
|
request: import("superstruct").Struct<{
|
282
278
|
method: string;
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
279
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
280
|
+
}, {
|
281
|
+
method: import("superstruct").Struct<string, null>;
|
282
|
+
params: import("superstruct").Struct<import("..").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
|
283
|
+
}>;
|
287
284
|
}>>;
|
288
285
|
export declare type ListRequestsResponse = Infer<typeof ListRequestsResponseStruct>;
|
289
286
|
export declare const GetRequestRequestStruct: import("superstruct").Struct<{
|
@@ -310,9 +307,7 @@ export declare const GetRequestResponseStruct: import("superstruct").Struct<{
|
|
310
307
|
account: string;
|
311
308
|
request: {
|
312
309
|
method: string;
|
313
|
-
|
314
|
-
method: string;
|
315
|
-
params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
310
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
316
311
|
};
|
317
312
|
}, {
|
318
313
|
id: import("superstruct").Struct<string, null>;
|
@@ -320,10 +315,11 @@ export declare const GetRequestResponseStruct: import("superstruct").Struct<{
|
|
320
315
|
account: import("superstruct").Struct<string, null>;
|
321
316
|
request: import("superstruct").Struct<{
|
322
317
|
method: string;
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
318
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
319
|
+
}, {
|
320
|
+
method: import("superstruct").Struct<string, null>;
|
321
|
+
params: import("superstruct").Struct<import("..").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
|
322
|
+
}>;
|
327
323
|
}>;
|
328
324
|
export declare type GetRequestResponse = Infer<typeof GetRequestResponseStruct>;
|
329
325
|
export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
|
@@ -336,9 +332,7 @@ export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
|
|
336
332
|
account: string;
|
337
333
|
request: {
|
338
334
|
method: string;
|
339
|
-
|
340
|
-
method: string;
|
341
|
-
params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
335
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
342
336
|
};
|
343
337
|
};
|
344
338
|
}, {
|
@@ -349,9 +343,7 @@ export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
|
|
349
343
|
account: string;
|
350
344
|
request: {
|
351
345
|
method: string;
|
352
|
-
|
353
|
-
method: string;
|
354
|
-
params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
346
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
355
347
|
};
|
356
348
|
}, {
|
357
349
|
id: import("superstruct").Struct<string, null>;
|
@@ -359,10 +351,11 @@ export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
|
|
359
351
|
account: import("superstruct").Struct<string, null>;
|
360
352
|
request: import("superstruct").Struct<{
|
361
353
|
method: string;
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
354
|
+
params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
|
355
|
+
}, {
|
356
|
+
method: import("superstruct").Struct<string, null>;
|
357
|
+
params: import("superstruct").Struct<import("..").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
|
358
|
+
}>;
|
366
359
|
}>;
|
367
360
|
jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
|
368
361
|
id: import("superstruct").Struct<string, null>;
|
@@ -370,7 +363,10 @@ export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
|
|
370
363
|
export declare type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;
|
371
364
|
export declare const SubmitRequestResponseStruct: import("superstruct").Struct<{
|
372
365
|
pending: true;
|
373
|
-
redirect
|
366
|
+
redirect?: {
|
367
|
+
message?: string;
|
368
|
+
url?: string;
|
369
|
+
};
|
374
370
|
} | {
|
375
371
|
pending: false;
|
376
372
|
result: import("@metamask/utils").Json;
|
@@ -2,39 +2,37 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
|
|
2
2
|
method: "event:accountCreated";
|
3
3
|
params: {
|
4
4
|
account: {
|
5
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
5
6
|
id: string;
|
6
7
|
address: string;
|
7
8
|
options: Record<string, import("@metamask/utils").Json>;
|
8
9
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
9
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
10
10
|
};
|
11
11
|
};
|
12
12
|
}, {
|
13
13
|
method: import("superstruct").Struct<"event:accountCreated", "event:accountCreated">;
|
14
14
|
params: import("superstruct").Struct<{
|
15
15
|
account: {
|
16
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
16
17
|
id: string;
|
17
18
|
address: string;
|
18
19
|
options: Record<string, import("@metamask/utils").Json>;
|
19
20
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
20
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
21
21
|
};
|
22
22
|
}, {
|
23
23
|
/**
|
24
24
|
* New account object.
|
25
25
|
*/
|
26
26
|
account: import("superstruct").Struct<{
|
27
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
27
28
|
id: string;
|
28
29
|
address: string;
|
29
30
|
options: Record<string, import("@metamask/utils").Json>;
|
30
31
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
31
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
32
32
|
}, {
|
33
33
|
id: import("superstruct").Struct<string, null>;
|
34
34
|
address: import("superstruct").Struct<string, null>;
|
35
|
-
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
36
|
-
* Request result.
|
37
|
-
*/
|
35
|
+
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
38
36
|
methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
|
39
37
|
personal_sign: "personal_sign";
|
40
38
|
eth_sign: "eth_sign";
|
@@ -55,39 +53,37 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
|
|
55
53
|
method: "event:accountUpdated";
|
56
54
|
params: {
|
57
55
|
account: {
|
56
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
58
57
|
id: string;
|
59
58
|
address: string;
|
60
59
|
options: Record<string, import("@metamask/utils").Json>;
|
61
60
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
62
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
63
61
|
};
|
64
62
|
};
|
65
63
|
}, {
|
66
64
|
method: import("superstruct").Struct<"event:accountUpdated", "event:accountUpdated">;
|
67
65
|
params: import("superstruct").Struct<{
|
68
66
|
account: {
|
67
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
69
68
|
id: string;
|
70
69
|
address: string;
|
71
70
|
options: Record<string, import("@metamask/utils").Json>;
|
72
71
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
73
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
74
72
|
};
|
75
73
|
}, {
|
76
74
|
/**
|
77
75
|
* Updated account object.
|
78
76
|
*/
|
79
77
|
account: import("superstruct").Struct<{
|
78
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
80
79
|
id: string;
|
81
80
|
address: string;
|
82
81
|
options: Record<string, import("@metamask/utils").Json>;
|
83
82
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
84
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
85
83
|
}, {
|
86
84
|
id: import("superstruct").Struct<string, null>;
|
87
85
|
address: import("superstruct").Struct<string, null>;
|
88
|
-
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
89
|
-
* Request result.
|
90
|
-
*/
|
86
|
+
options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
91
87
|
methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
|
92
88
|
personal_sign: "personal_sign";
|
93
89
|
eth_sign: "eth_sign";
|
package/dist/internal/types.d.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
import type { Infer } from 'superstruct';
|
2
2
|
export declare const InternalAccountStruct: import("superstruct").Struct<{
|
3
|
+
type: "eip155:eoa" | "eip155:eip4337";
|
3
4
|
id: string;
|
4
5
|
address: string;
|
5
6
|
options: Record<string, import("@metamask/utils").Json>;
|
6
7
|
methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
|
7
|
-
type: "eip155:eoa" | "eip155:eip4337";
|
8
8
|
metadata: {
|
9
9
|
name: string;
|
10
10
|
keyring: {
|
@@ -14,8 +14,8 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
|
|
14
14
|
id: string;
|
15
15
|
enabled: boolean;
|
16
16
|
name: string;
|
17
|
-
}
|
18
|
-
lastSelected?: number
|
17
|
+
};
|
18
|
+
lastSelected?: number;
|
19
19
|
};
|
20
20
|
}, {
|
21
21
|
metadata: import("superstruct").Struct<{
|
@@ -27,20 +27,20 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
|
|
27
27
|
id: string;
|
28
28
|
enabled: boolean;
|
29
29
|
name: string;
|
30
|
-
}
|
31
|
-
lastSelected?: number
|
30
|
+
};
|
31
|
+
lastSelected?: number;
|
32
32
|
}, {
|
33
|
-
|
33
|
+
name: import("superstruct").Struct<string, null>;
|
34
|
+
snap: import("superstruct").Struct<import("../superstruct").ExactOptionalTag | {
|
34
35
|
id: string;
|
35
36
|
enabled: boolean;
|
36
37
|
name: string;
|
37
|
-
}
|
38
|
+
}, {
|
38
39
|
id: import("superstruct").Struct<string, null>;
|
39
40
|
enabled: import("superstruct").Struct<boolean, null>;
|
40
41
|
name: import("superstruct").Struct<string, null>;
|
41
42
|
}>;
|
42
|
-
|
43
|
-
lastSelected: import("superstruct").Struct<number | undefined, null>;
|
43
|
+
lastSelected: import("superstruct").Struct<number | import("../superstruct").ExactOptionalTag, null>;
|
44
44
|
keyring: import("superstruct").Struct<{
|
45
45
|
type: string;
|
46
46
|
}, {
|
package/dist/internal/types.js
CHANGED
@@ -3,17 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InternalAccountStruct = void 0;
|
4
4
|
const superstruct_1 = require("superstruct");
|
5
5
|
const api_1 = require("../api");
|
6
|
-
|
6
|
+
const superstruct_2 = require("../superstruct");
|
7
|
+
exports.InternalAccountStruct = (0, superstruct_2.object)({
|
7
8
|
...api_1.KeyringAccountStruct.schema,
|
8
|
-
metadata: (0,
|
9
|
-
|
9
|
+
metadata: (0, superstruct_2.object)({
|
10
|
+
name: (0, superstruct_1.string)(),
|
11
|
+
snap: (0, superstruct_2.exactOptional)((0, superstruct_2.object)({
|
10
12
|
id: (0, superstruct_1.string)(),
|
11
13
|
enabled: (0, superstruct_1.boolean)(),
|
12
14
|
name: (0, superstruct_1.string)(),
|
13
15
|
})),
|
14
|
-
|
15
|
-
|
16
|
-
keyring: (0, superstruct_1.object)({
|
16
|
+
lastSelected: (0, superstruct_2.exactOptional)((0, superstruct_1.number)()),
|
17
|
+
keyring: (0, superstruct_2.object)({
|
17
18
|
type: (0, superstruct_1.string)(),
|
18
19
|
}),
|
19
20
|
}),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;AACA,
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;AACA,6CAAsD;AAEtD,gCAA8C;AAC9C,gDAAuD;AAE1C,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EAAC;IAC1C,GAAG,0BAAoB,CAAC,MAAM;IAC9B,QAAQ,EAAE,IAAA,oBAAM,EAAC;QACf,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,IAAI,EAAE,IAAA,2BAAa,EACjB,IAAA,oBAAM,EAAC;YACL,EAAE,EAAE,IAAA,oBAAM,GAAE;YACZ,OAAO,EAAE,IAAA,qBAAO,GAAE;YAClB,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC,CACH;QACD,YAAY,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;QACrC,OAAO,EAAE,IAAA,oBAAM,EAAC;YACd,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC;KACH,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Infer } from 'superstruct';\nimport { boolean, string, number } from 'superstruct';\n\nimport { KeyringAccountStruct } from '../api';\nimport { exactOptional, object } from '../superstruct';\n\nexport const InternalAccountStruct = object({\n ...KeyringAccountStruct.schema,\n metadata: object({\n name: string(),\n snap: exactOptional(\n object({\n id: string(),\n enabled: boolean(),\n name: string(),\n }),\n ),\n lastSelected: exactOptional(number()),\n keyring: object({\n type: string(),\n }),\n }),\n});\n\n/**\n * Internal account representation.\n *\n * This type is used internally by MetaMask to add additional metadata to the\n * account object. It's should not be used by external applications.\n */\nexport type InternalAccount = Infer<typeof InternalAccountStruct>;\n"]}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import type { Infer } from 'superstruct';
|
2
|
+
import { Struct } from 'superstruct';
|
3
|
+
import type { ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from 'superstruct/dist/utils';
|
4
|
+
declare const ExactOptionalSymbol: unique symbol;
|
5
|
+
export declare type ExactOptionalTag = {
|
6
|
+
type: typeof ExactOptionalSymbol;
|
7
|
+
};
|
8
|
+
/**
|
9
|
+
* Exclude type `Type` from the properties of `Obj`.
|
10
|
+
*
|
11
|
+
* ```ts
|
12
|
+
* type Foo = { a: string | null; b: number };
|
13
|
+
* type Bar = ExcludeType<Foo, null>;
|
14
|
+
* // Bar = { a: string, b: number }
|
15
|
+
* ```
|
16
|
+
*/
|
17
|
+
export declare type ExcludeType<Obj, Type> = {
|
18
|
+
[K in keyof Obj]: Exclude<Obj[K], Type>;
|
19
|
+
};
|
20
|
+
/**
|
21
|
+
* Make optional all properties that have the `ExactOptionalTag` type.
|
22
|
+
*
|
23
|
+
* ```ts
|
24
|
+
* type Foo = { a: string | ExactOptionalTag; b: number};
|
25
|
+
* type Bar = ExactOptionalize<Foo>;
|
26
|
+
* // Bar = { a?: string; b: number}
|
27
|
+
* ```
|
28
|
+
*/
|
29
|
+
export declare type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
|
30
|
+
/**
|
31
|
+
* Infer a type from an superstruct object schema.
|
32
|
+
*/
|
33
|
+
export declare type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
|
34
|
+
[K in keyof Schema]: Infer<Schema[K]>;
|
35
|
+
}>>>;
|
36
|
+
/**
|
37
|
+
* Change the return type of a superstruct object struct to support exact
|
38
|
+
* optional properties.
|
39
|
+
*
|
40
|
+
* @param schema - The object schema.
|
41
|
+
* @returns A struct representing an object with a known set of properties.
|
42
|
+
*/
|
43
|
+
export declare function object<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
|
44
|
+
/**
|
45
|
+
* Augment a struct to allow exact-optional values. Exact-optional values can
|
46
|
+
* be omitted but cannot be `undefined`.
|
47
|
+
*
|
48
|
+
* ```ts
|
49
|
+
* const foo = object({ bar: exactOptional(string()) });
|
50
|
+
* type Foo = Infer<typeof foo>;
|
51
|
+
* // Foo = { bar?: string }
|
52
|
+
* ```
|
53
|
+
*
|
54
|
+
* @param struct - The struct to augment.
|
55
|
+
* @returns The augmented struct.
|
56
|
+
*/
|
57
|
+
export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
|
58
|
+
export {};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.exactOptional = exports.object = void 0;
|
4
|
+
const superstruct_1 = require("superstruct");
|
5
|
+
/**
|
6
|
+
* Change the return type of a superstruct object struct to support exact
|
7
|
+
* optional properties.
|
8
|
+
*
|
9
|
+
* @param schema - The object schema.
|
10
|
+
* @returns A struct representing an object with a known set of properties.
|
11
|
+
*/
|
12
|
+
function object(schema) {
|
13
|
+
return (0, superstruct_1.object)(schema);
|
14
|
+
}
|
15
|
+
exports.object = object;
|
16
|
+
/**
|
17
|
+
* Check if the current property is present in its parent object.
|
18
|
+
*
|
19
|
+
* @param ctx - The context to check.
|
20
|
+
* @returns `true` if the property is present, `false` otherwise.
|
21
|
+
*/
|
22
|
+
function hasOptional(ctx) {
|
23
|
+
const property = ctx.path[ctx.path.length - 1];
|
24
|
+
const parent = ctx.branch[ctx.branch.length - 2];
|
25
|
+
return property in parent;
|
26
|
+
}
|
27
|
+
/**
|
28
|
+
* Augment a struct to allow exact-optional values. Exact-optional values can
|
29
|
+
* be omitted but cannot be `undefined`.
|
30
|
+
*
|
31
|
+
* ```ts
|
32
|
+
* const foo = object({ bar: exactOptional(string()) });
|
33
|
+
* type Foo = Infer<typeof foo>;
|
34
|
+
* // Foo = { bar?: string }
|
35
|
+
* ```
|
36
|
+
*
|
37
|
+
* @param struct - The struct to augment.
|
38
|
+
* @returns The augmented struct.
|
39
|
+
*/
|
40
|
+
function exactOptional(struct) {
|
41
|
+
return new superstruct_1.Struct({
|
42
|
+
...struct,
|
43
|
+
validator: (value, ctx) => !hasOptional(ctx) || struct.validator(value, ctx),
|
44
|
+
refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
|
45
|
+
});
|
46
|
+
}
|
47
|
+
exports.exactOptional = exactOptional;
|
48
|
+
//# sourceMappingURL=superstruct.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AACA,6CAAyD;AAkDzD;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAJD,wBAIC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC","sourcesContent":["import type { Infer, Context } from 'superstruct';\nimport { Struct, object as stObject } from 'superstruct';\nimport type {\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from 'superstruct/dist/utils';\n\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const superstruct_1 = require("superstruct");
|
4
|
+
const tsd_1 = require("tsd");
|
5
|
+
const _1 = require(".");
|
6
|
+
const exactOptionalObject = (0, _1.object)({
|
7
|
+
a: (0, superstruct_1.number)(),
|
8
|
+
b: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
9
|
+
c: (0, _1.exactOptional)((0, superstruct_1.boolean)()),
|
10
|
+
});
|
11
|
+
(0, tsd_1.expectAssignable)({ a: 0 });
|
12
|
+
(0, tsd_1.expectAssignable)({ a: 0, b: 'test' });
|
13
|
+
(0, tsd_1.expectAssignable)({ a: 0, b: 'test', c: true });
|
14
|
+
(0, tsd_1.expectAssignable)({ a: 0, b: undefined });
|
15
|
+
(0, tsd_1.expectNotAssignable)({ a: 0, b: 'test', c: 0 });
|
16
|
+
(0, tsd_1.expectNotAssignable)({ a: 0, b: 'test', c: undefined });
|
17
|
+
//# sourceMappingURL=superstruct.test-d.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"superstruct.test-d.js","sourceRoot":"","sources":["../src/superstruct.test-d.ts"],"names":[],"mappings":";;AACA,6CAAgE;AAChE,6BAA4D;AAE5D,wBAA0C;AAE1C,MAAM,mBAAmB,GAAG,IAAA,SAAM,EAAC;IACjC,CAAC,EAAE,IAAA,oBAAM,GAAE;IACX,CAAC,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACrB,CAAC,EAAE,IAAA,gBAAa,EAAC,IAAA,qBAAO,GAAE,CAAC;CAC5B,CAAC,CAAC;AAIH,IAAA,sBAAgB,EAAsB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAChD,IAAA,sBAAgB,EAAsB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3D,IAAA,sBAAgB,EAAsB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AACpE,IAAA,sBAAgB,EAAsB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;AAC9D,IAAA,yBAAmB,EAAsB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACpE,IAAA,yBAAmB,EAAsB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC","sourcesContent":["import type { Infer } from 'superstruct';\nimport { boolean, number, optional, string } from 'superstruct';\nimport { expectAssignable, expectNotAssignable } from 'tsd';\n\nimport { exactOptional, object } from '.';\n\nconst exactOptionalObject = object({\n a: number(),\n b: optional(string()),\n c: exactOptional(boolean()),\n});\n\ntype ExactOptionalObject = Infer<typeof exactOptionalObject>;\n\nexpectAssignable<ExactOptionalObject>({ a: 0 });\nexpectAssignable<ExactOptionalObject>({ a: 0, b: 'test' });\nexpectAssignable<ExactOptionalObject>({ a: 0, b: 'test', c: true });\nexpectAssignable<ExactOptionalObject>({ a: 0, b: undefined });\nexpectNotAssignable<ExactOptionalObject>({ a: 0, b: 'test', c: 0 });\nexpectNotAssignable<ExactOptionalObject>({ a: 0, b: 'test', c: undefined });\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask/keyring-api",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.4",
|
4
4
|
"description": "MetaMask Keyring API",
|
5
5
|
"keywords": [
|
6
6
|
"metamask",
|
@@ -32,15 +32,17 @@
|
|
32
32
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
|
33
33
|
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
|
34
34
|
"prepack": "./scripts/prepack.sh",
|
35
|
-
"test": "
|
35
|
+
"test": "yarn test:source && yarn test:types",
|
36
|
+
"test:source": "jest && jest-it-up",
|
37
|
+
"test:types": "tsd",
|
36
38
|
"test:watch": "jest --watch"
|
37
39
|
},
|
38
40
|
"dependencies": {
|
39
|
-
"@metamask/providers": "^
|
41
|
+
"@metamask/providers": "^12.0.0",
|
40
42
|
"@metamask/rpc-methods": "^0.38.1-flask.1",
|
41
43
|
"@metamask/snaps-controllers": "^0.38.2-flask.1",
|
42
44
|
"@metamask/snaps-utils": "^0.38.2-flask.1",
|
43
|
-
"@metamask/utils": "^8.
|
45
|
+
"@metamask/utils": "^8.1.0",
|
44
46
|
"@types/uuid": "^9.0.1",
|
45
47
|
"superstruct": "^1.0.3",
|
46
48
|
"uuid": "^9.0.0"
|
@@ -73,6 +75,7 @@
|
|
73
75
|
"rimraf": "^3.0.2",
|
74
76
|
"ts-jest": "^28.0.7",
|
75
77
|
"ts-node": "^10.7.0",
|
78
|
+
"tsd": "^0.29.0",
|
76
79
|
"typedoc": "^0.23.15",
|
77
80
|
"typescript": "~4.8.4"
|
78
81
|
},
|
@@ -96,5 +99,8 @@
|
|
96
99
|
"@metamask/rpc-methods>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
|
97
100
|
"@metamask/rpc-methods>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false
|
98
101
|
}
|
102
|
+
},
|
103
|
+
"tsd": {
|
104
|
+
"directory": "src"
|
99
105
|
}
|
100
106
|
}
|