@metamask/keyring-api 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -1
- package/dist/JsonRpcRequest.d.ts +8 -7
- 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/KeyringSnapRpcClient.d.ts +2 -1
- package/dist/KeyringSnapRpcClient.js.map +1 -1
- package/dist/api.d.ts +26 -29
- package/dist/api.js +20 -12
- 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 +48 -76
- package/dist/internal/api.js.map +1 -1
- package/dist/internal/events.d.ts +6 -12
- package/dist/internal/types.d.ts +10 -7
- package/dist/internal/types.js +7 -5
- package/dist/internal/types.js.map +1 -1
- package/dist/rpc-handler.d.ts +1 -1
- package/dist/rpc-handler.js.map +1 -1
- package/dist/superstruct.d.ts +57 -0
- package/dist/superstruct.js +49 -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/dist/utils.d.ts +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +10 -4
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AACzD,6CAKqB;AA+CrB;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAS;IAET,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,MAAoB;IAEpB,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,KAAU,EAAE,GAAG,CAAC;KACvD,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport {\n type Infer,\n type Context,\n Struct,\n object as stObject,\n} 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 a type from the properties of a type.\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<T, V> = {\n [K in keyof T]: Exclude<T[K], V>;\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<S extends object> = OmitBy<S, ExactOptionalTag> &\n Partial<ExcludeType<PickBy<S, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<S extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof S]: Infer<S[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<S extends ObjectSchema>(\n schema: S,\n): Struct<ObjectType<S>, S> {\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<T, S>(\n struct: Struct<T, S>,\n): Struct<T | ExactOptionalTag, S> {\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 T, 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/dist/utils.d.ts
CHANGED
package/dist/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAGtD;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,qBAAO,EAC/B,IAAA,oBAAM,GAAE,EACR,yEAAyE,CAC1E,CAAC;AAcF;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import { assert, pattern, string } from 'superstruct';\nimport type { Struct } from 'superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = pattern(\n string(),\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask/keyring-api",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.3",
|
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
|
}
|