@metamask/keyring-api 6.2.1 → 6.3.0

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.
Files changed (73) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/KeyringClient.js +9 -9
  3. package/dist/KeyringClient.js.map +1 -1
  4. package/dist/api/account.d.ts +62 -0
  5. package/dist/api/account.js +56 -0
  6. package/dist/api/account.js.map +1 -0
  7. package/dist/api/balance.d.ts +9 -0
  8. package/dist/api/balance.js +11 -0
  9. package/dist/api/balance.js.map +1 -0
  10. package/dist/api/export.d.ts +8 -0
  11. package/dist/api/export.js +7 -0
  12. package/dist/api/export.js.map +1 -0
  13. package/dist/api/index.d.ts +6 -0
  14. package/dist/api/index.js +23 -0
  15. package/dist/api/index.js.map +1 -0
  16. package/dist/{api.d.ts → api/keyring.d.ts} +34 -125
  17. package/dist/api/keyring.js +3 -0
  18. package/dist/api/keyring.js.map +1 -0
  19. package/dist/api/request.d.ts +39 -0
  20. package/dist/api/request.js +29 -0
  21. package/dist/api/request.js.map +1 -0
  22. package/dist/api/response.d.ts +24 -0
  23. package/dist/api/response.js +44 -0
  24. package/dist/api/response.js.map +1 -0
  25. package/dist/btc/types.d.ts +4 -7
  26. package/dist/btc/types.js +10 -12
  27. package/dist/btc/types.js.map +1 -1
  28. package/dist/eth/erc4337/types.d.ts +1 -1
  29. package/dist/eth/erc4337/types.js +2 -1
  30. package/dist/eth/erc4337/types.js.map +1 -1
  31. package/dist/eth/types.d.ts +9 -15
  32. package/dist/eth/types.js +23 -29
  33. package/dist/eth/types.js.map +1 -1
  34. package/dist/eth/utils.d.ts +3 -2
  35. package/dist/eth/utils.js +3 -2
  36. package/dist/eth/utils.js.map +1 -1
  37. package/dist/internal/api.d.ts +94 -112
  38. package/dist/internal/api.js +35 -22
  39. package/dist/internal/api.js.map +1 -1
  40. package/dist/internal/events.d.ts +40 -92
  41. package/dist/internal/rpc.d.ts +1 -0
  42. package/dist/internal/rpc.js +1 -0
  43. package/dist/internal/rpc.js.map +1 -1
  44. package/dist/internal/types.d.ts +65 -6
  45. package/dist/internal/types.js +7 -9
  46. package/dist/internal/types.js.map +1 -1
  47. package/dist/rpc-handler.d.ts +12 -0
  48. package/dist/rpc-handler.js +40 -2
  49. package/dist/rpc-handler.js.map +1 -1
  50. package/dist/superstruct.d.ts +9 -4
  51. package/dist/superstruct.js +14 -14
  52. package/dist/superstruct.js.map +1 -1
  53. package/dist/utils/caip.d.ts +37 -0
  54. package/dist/utils/caip.js +48 -0
  55. package/dist/utils/caip.js.map +1 -0
  56. package/dist/utils/index.d.ts +3 -0
  57. package/dist/utils/index.js +20 -0
  58. package/dist/utils/index.js.map +1 -0
  59. package/dist/utils/types.d.ts +17 -0
  60. package/dist/utils/types.js +29 -0
  61. package/dist/utils/types.js.map +1 -0
  62. package/dist/utils/typing.d.ts +32 -0
  63. package/dist/utils/typing.js +21 -0
  64. package/dist/utils/typing.js.map +1 -0
  65. package/package.json +1 -1
  66. package/dist/api.js +0 -108
  67. package/dist/api.js.map +0 -1
  68. package/dist/base-types.d.ts +0 -62
  69. package/dist/base-types.js +0 -32
  70. package/dist/base-types.js.map +0 -1
  71. package/dist/utils.d.ts +0 -26
  72. package/dist/utils.js +0 -26
  73. package/dist/utils.js.map +0 -1
@@ -0,0 +1,37 @@
1
+ import { type Infer } from 'superstruct';
2
+ /**
3
+ * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
4
+ */
5
+ export declare const CaipAssetTypeStruct: import("superstruct").Struct<string, null>;
6
+ export declare type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;
7
+ /**
8
+ * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
9
+ */
10
+ export declare const CaipAssetIdStruct: import("superstruct").Struct<string, null>;
11
+ export declare type CaipAssetId = Infer<typeof CaipAssetIdStruct>;
12
+ /**
13
+ * Check if the given value is a {@link CaipAssetType}.
14
+ *
15
+ * @param value - The value to check.
16
+ * @returns Whether the value is a {@link CaipAssetType}.
17
+ * @example
18
+ * ```ts
19
+ * isCaipAssetType('eip155:1/slip44:60'); // true
20
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true
21
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false
22
+ * ```
23
+ */
24
+ export declare function isCaipAssetType(value: unknown): value is CaipAssetType;
25
+ /**
26
+ * Check if the given value is a {@link CaipAssetId}.
27
+ *
28
+ * @param value - The value to check.
29
+ * @returns Whether the value is a {@link CaipAssetId}.
30
+ * @example
31
+ * ```ts
32
+ * isCaipAssetType('eip155:1/slip44:60'); // false
33
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false
34
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true
35
+ * ```
36
+ */
37
+ export declare function isCaipAssetId(value: unknown): value is CaipAssetId;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCaipAssetId = exports.isCaipAssetType = exports.CaipAssetIdStruct = exports.CaipAssetTypeStruct = void 0;
4
+ const superstruct_1 = require("superstruct");
5
+ const superstruct_2 = require("../superstruct");
6
+ const CAIP_ASSET_TYPE_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;
7
+ const CAIP_ASSET_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;
8
+ /**
9
+ * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
10
+ */
11
+ exports.CaipAssetTypeStruct = (0, superstruct_2.definePattern)('CaipAssetType', CAIP_ASSET_TYPE_REGEX);
12
+ /**
13
+ * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
14
+ */
15
+ exports.CaipAssetIdStruct = (0, superstruct_2.definePattern)('CaipAssetId', CAIP_ASSET_ID_REGEX);
16
+ /**
17
+ * Check if the given value is a {@link CaipAssetType}.
18
+ *
19
+ * @param value - The value to check.
20
+ * @returns Whether the value is a {@link CaipAssetType}.
21
+ * @example
22
+ * ```ts
23
+ * isCaipAssetType('eip155:1/slip44:60'); // true
24
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true
25
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false
26
+ * ```
27
+ */
28
+ function isCaipAssetType(value) {
29
+ return (0, superstruct_1.is)(value, exports.CaipAssetTypeStruct);
30
+ }
31
+ exports.isCaipAssetType = isCaipAssetType;
32
+ /**
33
+ * Check if the given value is a {@link CaipAssetId}.
34
+ *
35
+ * @param value - The value to check.
36
+ * @returns Whether the value is a {@link CaipAssetId}.
37
+ * @example
38
+ * ```ts
39
+ * isCaipAssetType('eip155:1/slip44:60'); // false
40
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false
41
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true
42
+ * ```
43
+ */
44
+ function isCaipAssetId(value) {
45
+ return (0, superstruct_1.is)(value, exports.CaipAssetIdStruct);
46
+ }
47
+ exports.isCaipAssetId = isCaipAssetId;
48
+ //# sourceMappingURL=caip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip.js","sourceRoot":"","sources":["../../src/utils/caip.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAE7C,gDAA+C;AAE/C,MAAM,qBAAqB,GACzB,2JAA2J,CAAC;AAE9J,MAAM,mBAAmB,GACvB,6LAA6L,CAAC;AAEhM;;GAEG;AACU,QAAA,mBAAmB,GAAG,IAAA,2BAAa,EAC9C,eAAe,EACf,qBAAqB,CACtB,CAAC;AAGF;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,2BAAa,EAC5C,aAAa,EACb,mBAAmB,CACpB,CAAC;AAGF;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,2BAAmB,CAAC,CAAC;AACxC,CAAC;AAFD,0CAEC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,yBAAiB,CAAC,CAAC;AACtC,CAAC;AAFD,sCAEC","sourcesContent":["import { is, type Infer } from 'superstruct';\n\nimport { definePattern } from '../superstruct';\n\nconst CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nconst CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct = definePattern(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n);\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct = definePattern(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n);\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // true\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false\n * ```\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // false\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true\n * ```\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export * from './caip';
2
+ export * from './types';
3
+ export * from './typing';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./caip"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./typing"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB;AACxB,2CAAyB","sourcesContent":["export * from './caip';\nexport * from './types';\nexport * from './typing';\n"]}
@@ -0,0 +1,17 @@
1
+ import { type Infer } from 'superstruct';
2
+ /**
3
+ * UUIDv4 struct.
4
+ */
5
+ export declare const UuidStruct: import("superstruct").Struct<string, null>;
6
+ /**
7
+ * Validates if a given value is a valid URL.
8
+ *
9
+ * @param value - The value to be validated.
10
+ * @returns A boolean indicating if the value is a valid URL.
11
+ */
12
+ export declare const UrlStruct: import("superstruct").Struct<string, null>;
13
+ /**
14
+ * A string which contains a positive float number.
15
+ */
16
+ export declare const StringNumberStruct: import("superstruct").Struct<string, null>;
17
+ export declare type StringNumber = Infer<typeof StringNumberStruct>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringNumberStruct = exports.UrlStruct = exports.UuidStruct = void 0;
4
+ const superstruct_1 = require("superstruct");
5
+ const superstruct_2 = require("../superstruct");
6
+ /**
7
+ * UUIDv4 struct.
8
+ */
9
+ exports.UuidStruct = (0, superstruct_2.definePattern)('UuidV4', /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu);
10
+ /**
11
+ * Validates if a given value is a valid URL.
12
+ *
13
+ * @param value - The value to be validated.
14
+ * @returns A boolean indicating if the value is a valid URL.
15
+ */
16
+ exports.UrlStruct = (0, superstruct_1.define)('Url', (value) => {
17
+ try {
18
+ const url = new URL(value);
19
+ return url.protocol === 'http:' || url.protocol === 'https:';
20
+ }
21
+ catch (_) {
22
+ return false;
23
+ }
24
+ });
25
+ /**
26
+ * A string which contains a positive float number.
27
+ */
28
+ exports.StringNumberStruct = (0, superstruct_2.definePattern)('StringNumber', /^\d+(\.\d+)?$/u);
29
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AAEjD,gDAA+C;AAE/C;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,2BAAa,EACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAEF;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI;QACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;KAC9D;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAA,2BAAa,EAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from 'superstruct';\n\nimport { definePattern } from '../superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\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 * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch (_) {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n"]}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Omit keys from a union type.
3
+ *
4
+ * The normal `Omit` type does not distribute over unions. So we use this
5
+ * workaround that applies `Omit` to each member of the union.
6
+ *
7
+ * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>
8
+ */
9
+ export declare type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
10
+ /**
11
+ * Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * type A = Extends<{a: string, b: string}, {a: string}>; // true
16
+ * type B = Extends<{a: string}, {a: string, b: string}>; // false
17
+ * ```
18
+ */
19
+ export declare type Extends<Child, Base> = Child extends Base ? true : false;
20
+ /**
21
+ * Assert that a type extends `true`. It can be used, for example, to assert
22
+ * that a given type extends another type.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok
27
+ * expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error
28
+ * ```
29
+ *
30
+ * This function follows the naming pattern used on `tsd`.
31
+ */
32
+ export declare function expectTrue<Type extends true>(): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expectTrue = void 0;
4
+ /**
5
+ * Assert that a type extends `true`. It can be used, for example, to assert
6
+ * that a given type extends another type.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok
11
+ * expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error
12
+ * ```
13
+ *
14
+ * This function follows the naming pattern used on `tsd`.
15
+ */
16
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
17
+ function expectTrue() {
18
+ // Intentionally empty
19
+ }
20
+ exports.expectTrue = expectTrue;
21
+ //# sourceMappingURL=typing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.js","sourceRoot":"","sources":["../../src/utils/typing.ts"],"names":[],"mappings":";;;AAuBA;;;;;;;;;;;GAWG;AACH,6DAA6D;AAC7D,SAAgB,UAAU;IACxB,sBAAsB;AACxB,CAAC;AAFD,gCAEC","sourcesContent":["/**\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 * Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.\n *\n * @example\n * ```ts\n * type A = Extends<{a: string, b: string}, {a: string}>; // true\n * type B = Extends<{a: string}, {a: string, b: string}>; // false\n * ```\n */\nexport type Extends<Child, Base> = Child extends Base ? true : false;\n\n/**\n * Assert that a type extends `true`. It can be used, for example, to assert\n * that a given type extends another type.\n *\n * @example\n * ```ts\n * expectTrue<Extends<{a: string, b: string}, {a: string}>>(); // Ok\n * expectTrue<Extends<{a: string}, {a: string, b: string}>>(); // Error\n * ```\n *\n * This function follows the naming pattern used on `tsd`.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function expectTrue<Type extends true>(): void {\n // Intentionally empty\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "6.2.1",
3
+ "version": "6.3.0",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",
package/dist/api.js DELETED
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KeyringResponseStruct = exports.KeyringAccountDataStruct = exports.KeyringRequestStruct = exports.KeyringAccountStruct = exports.BaseKeyringAccountStruct = exports.KeyringAccountStructs = void 0;
4
- const utils_1 = require("@metamask/utils");
5
- const superstruct_1 = require("superstruct");
6
- const btc_1 = require("./btc");
7
- const eth_1 = require("./eth");
8
- const superstruct_2 = require("./superstruct");
9
- const utils_2 = require("./utils");
10
- /**
11
- * Mapping between account types and their matching `superstruct` schema.
12
- */
13
- exports.KeyringAccountStructs = {
14
- [`${eth_1.EthAccountType.Eoa}`]: eth_1.EthEoaAccountStruct,
15
- [`${eth_1.EthAccountType.Erc4337}`]: eth_1.EthErc4337AccountStruct,
16
- [`${btc_1.BtcAccountType.P2wpkh}`]: btc_1.BtcP2wpkhAccountStruct,
17
- };
18
- /**
19
- * Base type for `KeyringAccount` as a `superstruct.object`.
20
- */
21
- exports.BaseKeyringAccountStruct = (0, superstruct_2.object)({
22
- /**
23
- * Account type.
24
- */
25
- type: (0, superstruct_1.enums)([
26
- `${eth_1.EthAccountType.Eoa}`,
27
- `${eth_1.EthAccountType.Erc4337}`,
28
- `${btc_1.BtcAccountType.P2wpkh}`,
29
- ]),
30
- });
31
- /**
32
- * Account as a `superstruct.object`.
33
- *
34
- * See {@link KeyringAccount}.
35
- */
36
- exports.KeyringAccountStruct = (0, superstruct_1.define)(
37
- // We do use a custom `define` for this type to avoid having to use a `union` since error
38
- // messages are a bit confusing.
39
- //
40
- // Doing manual validation allows us to use the "concrete" type of each supported acounts giving
41
- // use a much nicer message from `superstruct`.
42
- 'KeyringAccount', (value) => {
43
- // This will also raise if `value` does not match any of the supported account types!
44
- const account = (0, superstruct_1.mask)(value, exports.BaseKeyringAccountStruct);
45
- // At this point, we know that `value.type` can be used as an index for `KeyringAccountStructs`
46
- const [error] = (0, superstruct_1.validate)(value, exports.KeyringAccountStructs[account.type]);
47
- return error ?? true;
48
- });
49
- exports.KeyringRequestStruct = (0, superstruct_2.object)({
50
- /**
51
- * Keyring request ID (UUIDv4).
52
- */
53
- id: utils_2.UuidStruct,
54
- /**
55
- * Request's scope (CAIP-2 chain ID).
56
- */
57
- scope: (0, superstruct_1.string)(),
58
- /**
59
- * Account ID (UUIDv4).
60
- */
61
- account: utils_2.UuidStruct,
62
- /**
63
- * Inner request sent by the client application.
64
- */
65
- request: (0, superstruct_2.object)({
66
- method: (0, superstruct_1.string)(),
67
- 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)])),
68
- }),
69
- });
70
- exports.KeyringAccountDataStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct);
71
- exports.KeyringResponseStruct = (0, superstruct_1.union)([
72
- (0, superstruct_2.object)({
73
- /**
74
- * Pending flag.
75
- *
76
- * Setting the pending flag to true indicates that the request will be
77
- * handled asynchronously. The keyring must be called with `approveRequest`
78
- * or `rejectRequest` to resolve the request.
79
- */
80
- pending: (0, superstruct_1.literal)(true),
81
- /**
82
- * Redirect URL.
83
- *
84
- * If present in the response, MetaMask will display a confirmation dialog
85
- * with a link to the redirect URL. The user can choose to follow the link
86
- * or cancel the request.
87
- */
88
- redirect: (0, superstruct_2.exactOptional)((0, superstruct_2.object)({
89
- message: (0, superstruct_2.exactOptional)((0, superstruct_1.string)()),
90
- url: (0, superstruct_2.exactOptional)((0, superstruct_1.string)()),
91
- })),
92
- }),
93
- (0, superstruct_2.object)({
94
- /**
95
- * Pending flag.
96
- *
97
- * Setting the pending flag to false indicates that the request will be
98
- * handled synchronously. The keyring must return the result of the
99
- * request execution.
100
- */
101
- pending: (0, superstruct_1.literal)(false),
102
- /**
103
- * Request result.
104
- */
105
- result: utils_1.JsonStruct,
106
- }),
107
- ]);
108
- //# sourceMappingURL=api.js.map
package/dist/api.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAE7C,6CAUqB;AAIrB,+BAA+D;AAE/D,+BAIe;AACf,+CAAsD;AACtD,mCAAqC;AASrC;;GAEG;AACU,QAAA,qBAAqB,GAG9B;IACF,CAAC,GAAG,oBAAc,CAAC,GAAG,EAAE,CAAC,EAAE,yBAAmB;IAC9C,CAAC,GAAG,oBAAc,CAAC,OAAO,EAAE,CAAC,EAAE,6BAAuB;IACtD,CAAC,GAAG,oBAAc,CAAC,MAAM,EAAE,CAAC,EAAE,4BAAsB;CACrD,CAAC;AAEF;;GAEG;AACU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC;IAC7C;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC;QACV,GAAG,oBAAc,CAAC,GAAG,EAAE;QACvB,GAAG,oBAAc,CAAC,OAAO,EAAE;QAC3B,GAAG,oBAAc,CAAC,MAAM,EAAE;KAC3B,CAAC;CACH,CAAC,CAAC;AAEH;;;;GAIG;AACU,QAAA,oBAAoB,GAAG,IAAA,oBAAM;AACxC,yFAAyF;AACzF,gCAAgC;AAChC,EAAE;AACF,gGAAgG;AAChG,+CAA+C;AAC/C,gBAAgB,EAChB,CAAC,KAAc,EAAE,EAAE;IACjB,qFAAqF;IACrF,MAAM,OAAO,GAAG,IAAA,kBAAI,EAAC,KAAK,EAAE,gCAAwB,CAAC,CAAC;IAEtD,+FAA+F;IAC/F,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAQ,EACtB,KAAK,EACL,6BAAqB,CAAC,OAAO,CAAC,IAAI,CAAW,CAC9C,CAAC;IAEF,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC,CACF,CAAC;AASW,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, Struct } from 'superstruct';\nimport {\n enums,\n array,\n define,\n validate,\n literal,\n record,\n string,\n union,\n mask,\n} from 'superstruct';\n\nimport type { StaticAssertAbstractAccount } from './base-types';\nimport type { BtcP2wpkhAccount } from './btc';\nimport { BtcP2wpkhAccountStruct, BtcAccountType } from './btc';\nimport type { EthEoaAccount, EthErc4337Account } from './eth';\nimport {\n EthEoaAccountStruct,\n EthErc4337AccountStruct,\n EthAccountType,\n} from './eth';\nimport { exactOptional, object } from './superstruct';\nimport { UuidStruct } from './utils';\n\n/**\n * Type of supported accounts.\n */\nexport type KeyringAccounts = StaticAssertAbstractAccount<\n EthEoaAccount | EthErc4337Account | BtcP2wpkhAccount\n>;\n\n/**\n * Mapping between account types and their matching `superstruct` schema.\n */\nexport const KeyringAccountStructs: Record<\n string,\n Struct<EthEoaAccount> | Struct<EthErc4337Account> | Struct<BtcP2wpkhAccount>\n> = {\n [`${EthAccountType.Eoa}`]: EthEoaAccountStruct,\n [`${EthAccountType.Erc4337}`]: EthErc4337AccountStruct,\n [`${BtcAccountType.P2wpkh}`]: BtcP2wpkhAccountStruct,\n};\n\n/**\n * Base type for `KeyringAccount` as a `superstruct.object`.\n */\nexport const BaseKeyringAccountStruct = object({\n /**\n * Account type.\n */\n type: enums([\n `${EthAccountType.Eoa}`,\n `${EthAccountType.Erc4337}`,\n `${BtcAccountType.P2wpkh}`,\n ]),\n});\n\n/**\n * Account as a `superstruct.object`.\n *\n * See {@link KeyringAccount}.\n */\nexport const KeyringAccountStruct = define<KeyringAccounts>(\n // We do use a custom `define` for this type to avoid having to use a `union` since error\n // messages are a bit confusing.\n //\n // Doing manual validation allows us to use the \"concrete\" type of each supported acounts giving\n // use a much nicer message from `superstruct`.\n 'KeyringAccount',\n (value: unknown) => {\n // This will also raise if `value` does not match any of the supported account types!\n const account = mask(value, BaseKeyringAccountStruct);\n\n // At this point, we know that `value.type` can be used as an index for `KeyringAccountStructs`\n const [error] = validate(\n value,\n KeyringAccountStructs[account.type] as Struct,\n );\n\n return error ?? true;\n },\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"]}
@@ -1,62 +0,0 @@
1
- import type { Json } from '@metamask/utils';
2
- /**
3
- * Base type for any account. This type must be composed and extended to add a `methods`
4
- * and `type` fields.
5
- *
6
- * NOTE: This type isn't a `superstruct.object` as it is used to compose other objects. See
7
- * {@link BaseAccountStruct}.
8
- */
9
- export declare const BaseAccount: {
10
- /**
11
- * Account ID (UUIDv4).
12
- */
13
- id: import("superstruct").Struct<string, null>;
14
- /**
15
- * Account address or next receive address (UTXO).
16
- */
17
- address: import("superstruct").Struct<string, null>;
18
- /**
19
- * Keyring-dependent account options.
20
- */
21
- options: import("superstruct").Struct<Record<string, Json>, null>;
22
- };
23
- /**
24
- * Base type for any account as a `superstruct.object`.
25
- */
26
- export declare const BaseAccountStruct: import("superstruct").Struct<{
27
- id: string;
28
- address: string;
29
- options: Record<string, Json>;
30
- }, {
31
- /**
32
- * Account ID (UUIDv4).
33
- */
34
- id: import("superstruct").Struct<string, null>;
35
- /**
36
- * Account address or next receive address (UTXO).
37
- */
38
- address: import("superstruct").Struct<string, null>;
39
- /**
40
- * Keyring-dependent account options.
41
- */
42
- options: import("superstruct").Struct<Record<string, Json>, null>;
43
- }>;
44
- /**
45
- * Abstract struct that is used to match every supported account type. Making sure their type
46
- * definition do not diverge from each others.
47
- *
48
- * NOTE: This type is using "primitive types" such as `string` to not contrain any real account
49
- * type. It's up to those types to use more restrictions on their type definition.
50
- */
51
- export declare type AbstractAccount = {
52
- id: string;
53
- address: string;
54
- options: Record<string, Json>;
55
- type: string;
56
- methods: string[];
57
- };
58
- /**
59
- * Type helper to make sure `Type` is "equal to" `AbstractAccount`, asserting that `Type` (an account
60
- * type actually) never diverges from other account types.
61
- */
62
- export declare type StaticAssertAbstractAccount<Type extends AbstractAccount> = Type;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseAccountStruct = exports.BaseAccount = void 0;
4
- const utils_1 = require("@metamask/utils");
5
- const superstruct_1 = require("superstruct");
6
- const utils_2 = require("./utils");
7
- /**
8
- * Base type for any account. This type must be composed and extended to add a `methods`
9
- * and `type` fields.
10
- *
11
- * NOTE: This type isn't a `superstruct.object` as it is used to compose other objects. See
12
- * {@link BaseAccountStruct}.
13
- */
14
- exports.BaseAccount = {
15
- /**
16
- * Account ID (UUIDv4).
17
- */
18
- id: utils_2.UuidStruct,
19
- /**
20
- * Account address or next receive address (UTXO).
21
- */
22
- address: (0, superstruct_1.string)(),
23
- /**
24
- * Keyring-dependent account options.
25
- */
26
- options: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
27
- };
28
- /**
29
- * Base type for any account as a `superstruct.object`.
30
- */
31
- exports.BaseAccountStruct = (0, superstruct_1.object)(exports.BaseAccount);
32
- //# sourceMappingURL=base-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base-types.js","sourceRoot":"","sources":["../src/base-types.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAC7C,6CAAqD;AAErD,mCAAqC;AAErC;;;;;;GAMG;AACU,QAAA,WAAW,GAAG;IACzB;;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;CACtC,CAAC;AAEF;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,oBAAM,EAAC,mBAAW,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport { object, record, string } from 'superstruct';\n\nimport { UuidStruct } from './utils';\n\n/**\n * Base type for any account. This type must be composed and extended to add a `methods`\n * and `type` fields.\n *\n * NOTE: This type isn't a `superstruct.object` as it is used to compose other objects. See\n * {@link BaseAccountStruct}.\n */\nexport const BaseAccount = {\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/**\n * Base type for any account as a `superstruct.object`.\n */\nexport const BaseAccountStruct = object(BaseAccount);\n\n/**\n * Abstract struct that is used to match every supported account type. Making sure their type\n * definition do not diverge from each others.\n *\n * NOTE: This type is using \"primitive types\" such as `string` to not contrain any real account\n * type. It's up to those types to use more restrictions on their type definition.\n */\nexport type AbstractAccount = {\n id: string;\n address: string;\n options: Record<string, Json>;\n type: string;\n methods: string[];\n};\n\n/**\n * Type helper to make sure `Type` is \"equal to\" `AbstractAccount`, asserting that `Type` (an account\n * type actually) never diverges from other account types.\n */\nexport type StaticAssertAbstractAccount<Type extends AbstractAccount> = Type;\n"]}
package/dist/utils.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import type { Struct } from 'superstruct';
2
- /**
3
- * UUIDv4 struct.
4
- */
5
- export declare const UuidStruct: Struct<string, null>;
6
- /**
7
- * Omit keys from a union type.
8
- *
9
- * The normal `Omit` type does not distribute over unions. So we use this
10
- * workaround that applies `Omit` to each member of the union.
11
- *
12
- * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>
13
- */
14
- export declare type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
15
- /**
16
- * Assert that a value is valid according to a struct.
17
- *
18
- * It is similar to superstruct's mask function, but it does not ignore extra
19
- * properties.
20
- *
21
- * @param value - Value to check.
22
- * @param struct - Struct to validate the value against.
23
- * @param message - Error message to throw if the value is not valid.
24
- * @returns The value if it is valid.
25
- */
26
- export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
package/dist/utils.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strictMask = exports.UuidStruct = void 0;
4
- const superstruct_1 = require("superstruct");
5
- const superstruct_2 = require("./superstruct");
6
- /**
7
- * UUIDv4 struct.
8
- */
9
- exports.UuidStruct = (0, superstruct_2.definePattern)('UuidV4', /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu);
10
- /**
11
- * Assert that a value is valid according to a struct.
12
- *
13
- * It is similar to superstruct's mask function, but it does not ignore extra
14
- * properties.
15
- *
16
- * @param value - Value to check.
17
- * @param struct - Struct to validate the value against.
18
- * @param message - Error message to throw if the value is not valid.
19
- * @returns The value if it is valid.
20
- */
21
- function strictMask(value, struct, message) {
22
- (0, superstruct_1.assert)(value, struct, message);
23
- return value;
24
- }
25
- exports.strictMask = strictMask;
26
- //# sourceMappingURL=utils.js.map
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,6CAAqC;AAGrC,+CAA8C;AAE9C;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,2BAAa,EACrC,QAAQ,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 } from 'superstruct';\nimport type { Struct } from 'superstruct';\n\nimport { definePattern } from './superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\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"]}