@metamask/keyring-api 4.0.1 → 5.0.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [5.0.0]
11
+
12
+ ### Changed
13
+
14
+ - **BREAKING**: Add new `KeyringExecutionContext` to user operation methods ([#275](https://github.com/MetaMask/keyring-api/pull/275))
15
+ - Fix bundler type (defined as `string` now) ([#277](https://github.com/MetaMask/keyring-api/pull/277))
16
+ - Bump @metamask/providers from 15.0.0 to 16.0.0 ([#276](https://github.com/MetaMask/keyring-api/pull/276))
17
+ - Bump @metamask/safe-event-emitter from 3.1.0 to 3.1.1 ([#274](https://github.com/MetaMask/keyring-api/pull/274))
18
+
19
+ ## [4.0.2]
20
+
21
+ ### Changed
22
+
23
+ - Bump @metamask/snaps-sdk to ^3.1.1 ([#271](https://github.com/MetaMask/keyring-api/pull/271))
24
+ - Bump @metamask/safe-event-emitter from 3.0.0 to 3.1.0 ([#270](https://github.com/MetaMask/keyring-api/pull/270))
25
+ - Fix bundler URL validation ([#262](https://github.com/MetaMask/keyring-api/pull/262))
26
+
10
27
  ## [4.0.1]
11
28
 
12
29
  ### Changed
@@ -227,7 +244,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
227
244
  - SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
228
245
  - Helper functions to create keyring handler in the snap.
229
246
 
230
- [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v4.0.1...HEAD
247
+ [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v5.0.0...HEAD
248
+ [5.0.0]: https://github.com/MetaMask/keyring-api/compare/v4.0.2...v5.0.0
249
+ [4.0.2]: https://github.com/MetaMask/keyring-api/compare/v4.0.1...v4.0.2
231
250
  [4.0.1]: https://github.com/MetaMask/keyring-api/compare/v4.0.0...v4.0.1
232
251
  [4.0.0]: https://github.com/MetaMask/keyring-api/compare/v3.0.0...v4.0.0
233
252
  [3.0.0]: https://github.com/MetaMask/keyring-api/compare/v2.0.0...v3.0.0
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Context used by a Keyring implementation.
3
+ */
4
+ export declare type KeyringExecutionContext = {
5
+ /** The chain ID. */
6
+ chainId: string;
7
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=contexts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contexts.js","sourceRoot":"","sources":["../src/contexts.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Context used by a Keyring implementation.\n */\nexport type KeyringExecutionContext = {\n /** The chain ID. */\n chainId: string;\n};\n"]}
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EthUserOperationPatchStruct = exports.EthBaseUserOperationStruct = exports.EthBaseTransactionStruct = exports.EthUserOperationStruct = void 0;
4
- const superstruct_1 = require("superstruct");
5
- const superstruct_2 = require("../../superstruct");
4
+ const superstruct_1 = require("../../superstruct");
6
5
  const types_1 = require("../types");
7
6
  /**
8
7
  * Struct of a UserOperation as defined by ERC-4337.
9
8
  * @see https://eips.ethereum.org/EIPS/eip-4337#definitions
10
9
  */
11
- exports.EthUserOperationStruct = (0, superstruct_2.object)({
10
+ exports.EthUserOperationStruct = (0, superstruct_1.object)({
12
11
  sender: types_1.EthAddressStruct,
13
12
  nonce: types_1.EthUint256Struct,
14
13
  initCode: types_1.EthBytesStruct,
@@ -25,7 +24,7 @@ exports.EthUserOperationStruct = (0, superstruct_2.object)({
25
24
  * Struct containing the most basic transaction information required to
26
25
  * construct a UserOperation.
27
26
  */
28
- exports.EthBaseTransactionStruct = (0, superstruct_2.object)({
27
+ exports.EthBaseTransactionStruct = (0, superstruct_1.object)({
29
28
  /**
30
29
  * Address of the transaction recipient.
31
30
  */
@@ -39,23 +38,23 @@ exports.EthBaseTransactionStruct = (0, superstruct_2.object)({
39
38
  */
40
39
  data: types_1.EthBytesStruct,
41
40
  });
42
- exports.EthBaseUserOperationStruct = (0, superstruct_2.object)({
41
+ exports.EthBaseUserOperationStruct = (0, superstruct_1.object)({
43
42
  nonce: types_1.EthUint256Struct,
44
43
  initCode: types_1.EthBytesStruct,
45
44
  callData: types_1.EthBytesStruct,
46
- gasLimits: (0, superstruct_2.exactOptional)((0, superstruct_2.object)({
45
+ gasLimits: (0, superstruct_1.exactOptional)((0, superstruct_1.object)({
47
46
  callGasLimit: types_1.EthUint256Struct,
48
47
  verificationGasLimit: types_1.EthUint256Struct,
49
48
  preVerificationGas: types_1.EthUint256Struct,
50
49
  })),
51
50
  dummyPaymasterAndData: types_1.EthBytesStruct,
52
51
  dummySignature: types_1.EthBytesStruct,
53
- bundlerUrl: (0, superstruct_1.string)(),
52
+ bundlerUrl: superstruct_1.UrlStruct,
54
53
  });
55
- exports.EthUserOperationPatchStruct = (0, superstruct_2.object)({
54
+ exports.EthUserOperationPatchStruct = (0, superstruct_1.object)({
56
55
  paymasterAndData: types_1.EthBytesStruct,
57
- callGasLimit: (0, superstruct_2.exactOptional)(types_1.EthUint256Struct),
58
- verificationGasLimit: (0, superstruct_2.exactOptional)(types_1.EthUint256Struct),
59
- preVerificationGas: (0, superstruct_2.exactOptional)(types_1.EthUint256Struct),
56
+ callGasLimit: (0, superstruct_1.exactOptional)(types_1.EthUint256Struct),
57
+ verificationGasLimit: (0, superstruct_1.exactOptional)(types_1.EthUint256Struct),
58
+ preVerificationGas: (0, superstruct_1.exactOptional)(types_1.EthUint256Struct),
60
59
  });
61
60
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/eth/erc4337/types.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AAEjD,mDAA0D;AAC1D,oCAA8E;AAE9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Infer } from 'superstruct';\n\nimport { exactOptional, object } from '../../superstruct';\nimport { EthAddressStruct, EthBytesStruct, EthUint256Struct } from '../types';\n\n/**\n * Struct of a UserOperation as defined by ERC-4337.\n * @see https://eips.ethereum.org/EIPS/eip-4337#definitions\n */\nexport const EthUserOperationStruct = object({\n sender: EthAddressStruct,\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n maxFeePerGas: EthUint256Struct,\n maxPriorityFeePerGas: EthUint256Struct,\n paymasterAndData: EthBytesStruct,\n signature: EthBytesStruct,\n});\n\nexport type EthUserOperation = Infer<typeof EthUserOperationStruct>;\n\n/**\n * Struct containing the most basic transaction information required to\n * construct a UserOperation.\n */\nexport const EthBaseTransactionStruct = object({\n /**\n * Address of the transaction recipient.\n */\n to: EthAddressStruct,\n\n /**\n * Amount of wei to transfer to the recipient.\n */\n value: EthUint256Struct,\n\n /**\n * Data to pass to the recipient.\n */\n data: EthBytesStruct,\n});\n\nexport type EthBaseTransaction = Infer<typeof EthBaseTransactionStruct>;\n\nexport const EthBaseUserOperationStruct = object({\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n gasLimits: exactOptional(\n object({\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n }),\n ),\n dummyPaymasterAndData: EthBytesStruct,\n dummySignature: EthBytesStruct,\n bundlerUrl: string(),\n});\n\nexport type EthBaseUserOperation = Infer<typeof EthBaseUserOperationStruct>;\n\nexport const EthUserOperationPatchStruct = object({\n paymasterAndData: EthBytesStruct,\n callGasLimit: exactOptional(EthUint256Struct),\n verificationGasLimit: exactOptional(EthUint256Struct),\n preVerificationGas: exactOptional(EthUint256Struct),\n});\n\nexport type EthUserOperationPatch = Infer<typeof EthUserOperationPatchStruct>;\n"]}
1
+ {"version":3,"file":"types.js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kB,EAAE,IAAA,2BAAa,EAAC,wBAAgB,CAAC;CACpD,CAAC,CAAC","sourcesContent":["import { type Infer } from 'superstruct';\n\nimport { UrlStruct, exactOptional, object } from '../../superstruct';\nimport { EthAddressStruct, EthBytesStruct, EthUint256Struct } from '../types';\n\n/**\n * Struct of a UserOperation as defined by ERC-4337.\n * @see https://eips.ethereum.org/EIPS/eip-4337#definitions\n */\nexport const EthUserOperationStruct = object({\n sender: EthAddressStruct,\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n maxFeePerGas: EthUint256Struct,\n maxPriorityFeePerGas: EthUint256Struct,\n paymasterAndData: EthBytesStruct,\n signature: EthBytesStruct,\n});\n\nexport type EthUserOperation = Infer<typeof EthUserOperationStruct>;\n\n/**\n * Struct containing the most basic transaction information required to\n * construct a UserOperation.\n */\nexport const EthBaseTransactionStruct = object({\n /**\n * Address of the transaction recipient.\n */\n to: EthAddressStruct,\n\n /**\n * Amount of wei to transfer to the recipient.\n */\n value: EthUint256Struct,\n\n /**\n * Data to pass to the recipient.\n */\n data: EthBytesStruct,\n});\n\nexport type EthBaseTransaction = Infer<typeof EthBaseTransactionStruct>;\n\nexport const EthBaseUserOperationStruct = object({\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n gasLimits: exactOptional(\n object({\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n }),\n ),\n dummyPaymasterAndData: EthBytesStruct,\n dummySignature: EthBytesStruct,\n bundlerUrl: UrlStruct,\n});\n\nexport type EthBaseUserOperation = Infer<typeof EthBaseUserOperationStruct>;\n\nexport const EthUserOperationPatchStruct = object({\n paymasterAndData: EthBytesStruct,\n callGasLimit: exactOptional(EthUint256Struct),\n verificationGasLimit: exactOptional(EthUint256Struct),\n preVerificationGas: exactOptional(EthUint256Struct),\n});\n\nexport type EthUserOperationPatch = Infer<typeof EthUserOperationPatchStruct>;\n"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './api';
2
+ export * from './contexts';
2
3
  export * from './eth';
3
4
  export * from './events';
4
5
  export * from './internal';
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api"), exports);
18
+ __exportStar(require("./contexts"), exports);
18
19
  __exportStar(require("./eth"), exports);
19
20
  __exportStar(require("./events"), exports);
20
21
  __exportStar(require("./internal"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,wCAAsB;AACtB,2CAAyB;AACzB,6CAA2B;AAC3B,kDAAgC;AAChC,yDAAuC;AACvC,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B","sourcesContent":["export * from './api';\nexport * from './eth';\nexport * from './events';\nexport * from './internal';\nexport * from './KeyringClient';\nexport * from './KeyringSnapRpcClient';\nexport * from './rpc-handler';\nexport * from './snap-utils';\nexport * from './superstruct';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,6CAA2B;AAC3B,wCAAsB;AACtB,2CAAyB;AACzB,6CAA2B;AAC3B,kDAAgC;AAChC,yDAAuC;AACvC,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B","sourcesContent":["export * from './api';\nexport * from './contexts';\nexport * from './eth';\nexport * from './events';\nexport * from './internal';\nexport * from './KeyringClient';\nexport * from './KeyringSnapRpcClient';\nexport * from './rpc-handler';\nexport * from './snap-utils';\nexport * from './superstruct';\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { Json, Keyring } from '@metamask/utils';
2
+ import type { KeyringExecutionContext } from '../../contexts';
2
3
  import type { EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch } from '../../eth';
3
4
  export declare type EthKeyring<State extends Json> = Keyring<State> & {
4
5
  /**
@@ -6,24 +7,27 @@ export declare type EthKeyring<State extends Json> = Keyring<State> & {
6
7
  *
7
8
  * @param address - Address of the sender.
8
9
  * @param transactions - Base transactions to include in the UserOperation.
10
+ * @param context - Keyring execution context.
9
11
  * @returns A pseudo-UserOperation that can be used to construct a real.
10
12
  */
11
- prepareUserOperation?(address: string, transactions: EthBaseTransaction[]): Promise<EthBaseUserOperation>;
13
+ prepareUserOperation?(address: string, transactions: EthBaseTransaction[], context: KeyringExecutionContext): Promise<EthBaseUserOperation>;
12
14
  /**
13
15
  * Patches properties of a UserOperation. Currently, only the
14
16
  * `paymasterAndData` can be patched.
15
17
  *
16
18
  * @param address - Address of the sender.
17
19
  * @param userOp - UserOperation to patch.
20
+ * @param context - Keyring execution context.
18
21
  * @returns A patch to apply to the UserOperation.
19
22
  */
20
- patchUserOperation?(address: string, userOp: EthUserOperation): Promise<EthUserOperationPatch>;
23
+ patchUserOperation?(address: string, userOp: EthUserOperation, context: KeyringExecutionContext): Promise<EthUserOperationPatch>;
21
24
  /**
22
25
  * Signs an UserOperation.
23
26
  *
24
27
  * @param address - Address of the sender.
25
28
  * @param userOp - UserOperation to sign.
29
+ * @param context - Keyring execution context.
26
30
  * @returns The signature of the UserOperation.
27
31
  */
28
- signUserOperation?(address: string, userOp: EthUserOperation): Promise<string>;
32
+ signUserOperation?(address: string, userOp: EthUserOperation, context: KeyringExecutionContext): Promise<string>;
29
33
  };
@@ -1 +1 @@
1
- {"version":3,"file":"EthKeyring.js","sourceRoot":"","sources":["../../../src/internal/eth/EthKeyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json, Keyring } from '@metamask/utils';\n\nimport type {\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n} from '../../eth';\n\nexport type EthKeyring<State extends Json> = Keyring<State> & {\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n prepareUserOperation?(\n address: string,\n transactions: EthBaseTransaction[],\n ): Promise<EthBaseUserOperation>;\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @returns A patch to apply to the UserOperation.\n */\n patchUserOperation?(\n address: string,\n userOp: EthUserOperation,\n ): Promise<EthUserOperationPatch>;\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @returns The signature of the UserOperation.\n */\n signUserOperation?(\n address: string,\n userOp: EthUserOperation,\n ): Promise<string>;\n};\n"]}
1
+ {"version":3,"file":"EthKeyring.js","sourceRoot":"","sources":["../../../src/internal/eth/EthKeyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json, Keyring } from '@metamask/utils';\n\nimport type { KeyringExecutionContext } from '../../contexts';\nimport type {\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n} from '../../eth';\n\nexport type EthKeyring<State extends Json> = Keyring<State> & {\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n prepareUserOperation?(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation>;\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n */\n patchUserOperation?(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch>;\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Keyring execution context.\n * @returns The signature of the UserOperation.\n */\n signUserOperation?(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string>;\n};\n"]}
@@ -69,4 +69,11 @@ export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>
69
69
  * @returns A new string-struct that matches the given pattern.
70
70
  */
71
71
  export declare function definePattern(name: string, pattern: RegExp): Struct<string, null>;
72
+ /**
73
+ * Validates if a given value is a valid URL.
74
+ *
75
+ * @param value - The value to be validated.
76
+ * @returns A boolean indicating if the value is a valid URL.
77
+ */
78
+ export declare const UrlStruct: Struct<string, null>;
72
79
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.definePattern = exports.exactOptional = exports.object = void 0;
3
+ exports.UrlStruct = exports.definePattern = exports.exactOptional = exports.object = void 0;
4
4
  const superstruct_1 = require("superstruct");
5
5
  /**
6
6
  * Change the return type of a superstruct object struct to support exact
@@ -62,4 +62,20 @@ function definePattern(name, pattern) {
62
62
  return (0, superstruct_1.define)(name, (value) => typeof value === 'string' && pattern.test(value));
63
63
  }
64
64
  exports.definePattern = definePattern;
65
+ /**
66
+ * Validates if a given value is a valid URL.
67
+ *
68
+ * @param value - The value to be validated.
69
+ * @returns A boolean indicating if the value is a valid URL.
70
+ */
71
+ exports.UrlStruct = (0, superstruct_1.define)('Url', (value) => {
72
+ let url;
73
+ try {
74
+ url = new URL(value);
75
+ }
76
+ catch (_) {
77
+ return false;
78
+ }
79
+ return url.protocol === 'http:' || url.protocol === 'https:';
80
+ });
65
81
  //# sourceMappingURL=superstruct.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AACA,6CAAiE;AAkDjE;;;;;;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;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AATD,sCASC","sourcesContent":["import type { Infer, Context } from 'superstruct';\nimport { Struct, define, 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\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n"]}
1
+ {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AACA,6CAAiE;AAkDjE;;;;;;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;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AATD,sCASC;AAED;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,GAAG,CAAC;IAER,IAAI;QACF,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;KAChC;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;IAED,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;AAC/D,CAAC,CAAC,CAAC","sourcesContent":["import type { Infer, Context } from 'superstruct';\nimport { Struct, define, 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\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\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 let url;\n\n try {\n url = new URL(value as string);\n } catch (_) {\n return false;\n }\n\n return url.protocol === 'http:' || url.protocol === 'https:';\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",
@@ -38,8 +38,8 @@
38
38
  "test:watch": "jest --watch"
39
39
  },
40
40
  "dependencies": {
41
- "@metamask/providers": "^15.0.0",
42
- "@metamask/snaps-sdk": "^3.1.0",
41
+ "@metamask/providers": "^16.0.0",
42
+ "@metamask/snaps-sdk": "^3.1.1",
43
43
  "@metamask/utils": "^8.3.0",
44
44
  "@types/uuid": "^9.0.1",
45
45
  "superstruct": "^1.0.3",