@metamask/keyring-api 0.2.3 → 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 +38 -33
- package/dist/superstruct.d.ts +10 -9
- package/dist/superstruct.js +0 -1
- package/dist/superstruct.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -6,66 +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
|
+
|
9
13
|
## [0.2.3]
|
10
14
|
### Added
|
11
|
-
- Add redirection message to snap async response ([#102](https://github.com/MetaMask/keyring-api/pull/102))
|
15
|
+
- Add redirection message to snap async response ([#102](https://github.com/MetaMask/keyring-api/pull/102)).
|
12
16
|
|
13
17
|
### Changed
|
14
|
-
- Use `Omit` instead of `OmitUnion` ([#106](https://github.com/MetaMask/keyring-api/pull/106))
|
15
|
-
- Update `KeyringResponse` comment ([#103](https://github.com/MetaMask/keyring-api/pull/103))
|
16
|
-
- Use `KeyringRpcMethod` enum instead of string ([#105](https://github.com/MetaMask/keyring-api/pull/105))
|
17
|
-
- Refactor tests to match superstruct examples ([#104](https://github.com/MetaMask/keyring-api/pull/104))
|
18
|
-
- Add `exactOptional()` superstruct type ([#100](https://github.com/MetaMask/keyring-api/pull/100))
|
19
|
-
- Bump @metamask/providers from 11.1.2 to 12.0.0 ([#99](https://github.com/MetaMask/keyring-api/pull/99))
|
20
|
-
- Bump @metamask/providers from 11.1.1 to 11.1.2 ([#98](https://github.com/MetaMask/keyring-api/pull/98))
|
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)).
|
21
25
|
|
22
26
|
## [0.2.2]
|
23
27
|
### Added
|
24
|
-
- Add architecture and EVM methods docs ([#86](https://github.com/MetaMask/keyring-api/pull/86))
|
25
|
-
- 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)).
|
26
30
|
|
27
31
|
### Changed
|
28
|
-
- Make request `params` optional ([#96](https://github.com/MetaMask/keyring-api/pull/96))
|
29
|
-
- Remove `lastActive` field from internal account model ([#95](https://github.com/MetaMask/keyring-api/pull/95))
|
30
|
-
- 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)).
|
31
35
|
|
32
36
|
## [0.2.1]
|
33
37
|
### Changed
|
34
|
-
- 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)).
|
35
39
|
|
36
40
|
## [0.2.0]
|
37
41
|
### Added
|
38
|
-
- Add `InternalAccount` type and create submodule `internal` ([#65](https://github.com/MetaMask/keyring-api/pull/65))
|
39
|
-
- Add keyring events and helper functions ([#74](https://github.com/MetaMask/keyring-api/pull/74))
|
40
|
-
- Add a `redirect` field to asynchronous request responses ([#75](https://github.com/MetaMask/keyring-api/pull/75))
|
41
|
-
- Add `exportAccount` method ([#60](https://github.com/MetaMask/keyring-api/pull/60))
|
42
|
-
- 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)).
|
43
47
|
|
44
48
|
### Changed
|
45
|
-
- Rename `erc4337` -> `eip4337` ([#42](https://github.com/MetaMask/keyring-api/pull/42))
|
46
|
-
- Make `options` a mandatory field of `KeyringAccount` ([#30](https://github.com/MetaMask/keyring-api/pull/30))
|
47
|
-
- Make `approveRequest` and `rejectRequest` optional ([#63](https://github.com/MetaMask/keyring-api/pull/63))
|
48
|
-
- Make `exportAccount`, `listRequests` and `getRequest` optional ([#73](https://github.com/MetaMask/keyring-api/pull/73))
|
49
|
-
- Export enums with account methods and types ([#66](https://github.com/MetaMask/keyring-api/pull/66))
|
50
|
-
- Make `approveRequest` accept a `result` argument ([#59](https://github.com/MetaMask/keyring-api/pull/59))
|
51
|
-
- Remove account name from `KeyringAccount` type ([#55](https://github.com/MetaMask/keyring-api/pull/55))
|
52
|
-
- Remove `eth_sendTransaction` method ([#50](https://github.com/MetaMask/keyring-api/pull/50))
|
53
|
-
- 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)).
|
54
58
|
|
55
59
|
## [0.1.3]
|
56
60
|
### Changed
|
57
|
-
- 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)).
|
58
62
|
|
59
63
|
## [0.1.2]
|
60
64
|
### Changed
|
61
|
-
- Update snaps dependencies
|
65
|
+
- Update snaps dependencies ([#21](https://github.com/MetaMask/keyring-api/pull/21)).
|
62
66
|
|
63
67
|
## [0.1.1]
|
64
68
|
### Added
|
65
|
-
- Validate snap responses for type correctness
|
69
|
+
- Validate snap responses for type correctness ([#15](https://github.com/MetaMask/keyring-api/pull/15)).
|
66
70
|
|
67
71
|
### Changed
|
68
|
-
- Rename RPC handling functions
|
72
|
+
- Rename RPC handling functions ([#16](https://github.com/MetaMask/keyring-api/pull/16)).
|
69
73
|
|
70
74
|
## [0.1.0] - 2023-06-20
|
71
75
|
### Added
|
@@ -75,7 +79,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
75
79
|
- SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
|
76
80
|
- Helper functions to create keyring handler in the snap.
|
77
81
|
|
78
|
-
[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
|
79
84
|
[0.2.3]: https://github.com/MetaMask/keyring-api/compare/v0.2.2...v0.2.3
|
80
85
|
[0.2.2]: https://github.com/MetaMask/keyring-api/compare/v0.2.1...v0.2.2
|
81
86
|
[0.2.1]: https://github.com/MetaMask/keyring-api/compare/v0.2.0...v0.2.1
|
package/dist/superstruct.d.ts
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
1
|
+
import type { Infer } from 'superstruct';
|
2
|
+
import { Struct } from 'superstruct';
|
2
3
|
import type { ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from 'superstruct/dist/utils';
|
3
4
|
declare const ExactOptionalSymbol: unique symbol;
|
4
5
|
export declare type ExactOptionalTag = {
|
5
6
|
type: typeof ExactOptionalSymbol;
|
6
7
|
};
|
7
8
|
/**
|
8
|
-
* Exclude
|
9
|
+
* Exclude type `Type` from the properties of `Obj`.
|
9
10
|
*
|
10
11
|
* ```ts
|
11
12
|
* type Foo = { a: string | null; b: number };
|
@@ -13,8 +14,8 @@ export declare type ExactOptionalTag = {
|
|
13
14
|
* // Bar = { a: string, b: number }
|
14
15
|
* ```
|
15
16
|
*/
|
16
|
-
export declare type ExcludeType<
|
17
|
-
[K in keyof
|
17
|
+
export declare type ExcludeType<Obj, Type> = {
|
18
|
+
[K in keyof Obj]: Exclude<Obj[K], Type>;
|
18
19
|
};
|
19
20
|
/**
|
20
21
|
* Make optional all properties that have the `ExactOptionalTag` type.
|
@@ -25,12 +26,12 @@ export declare type ExcludeType<T, V> = {
|
|
25
26
|
* // Bar = { a?: string; b: number}
|
26
27
|
* ```
|
27
28
|
*/
|
28
|
-
export declare type ExactOptionalize<
|
29
|
+
export declare type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
|
29
30
|
/**
|
30
31
|
* Infer a type from an superstruct object schema.
|
31
32
|
*/
|
32
|
-
export declare type ObjectType<
|
33
|
-
[K in keyof
|
33
|
+
export declare type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
|
34
|
+
[K in keyof Schema]: Infer<Schema[K]>;
|
34
35
|
}>>>;
|
35
36
|
/**
|
36
37
|
* Change the return type of a superstruct object struct to support exact
|
@@ -39,7 +40,7 @@ export declare type ObjectType<S extends ObjectSchema> = Simplify<ExactOptionali
|
|
39
40
|
* @param schema - The object schema.
|
40
41
|
* @returns A struct representing an object with a known set of properties.
|
41
42
|
*/
|
42
|
-
export declare function object<
|
43
|
+
export declare function object<Schema extends ObjectSchema>(schema: Schema): Struct<ObjectType<Schema>, Schema>;
|
43
44
|
/**
|
44
45
|
* Augment a struct to allow exact-optional values. Exact-optional values can
|
45
46
|
* be omitted but cannot be `undefined`.
|
@@ -53,5 +54,5 @@ export declare function object<S extends ObjectSchema>(schema: S): Struct<Object
|
|
53
54
|
* @param struct - The struct to augment.
|
54
55
|
* @returns The augmented struct.
|
55
56
|
*/
|
56
|
-
export declare function exactOptional<
|
57
|
+
export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
|
57
58
|
export {};
|
package/dist/superstruct.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.exactOptional = exports.object = void 0;
|
4
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
5
4
|
const superstruct_1 = require("superstruct");
|
6
5
|
/**
|
7
6
|
* Change the return type of a superstruct object struct to support exact
|
package/dist/superstruct.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;
|
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"]}
|