@metamask/snaps-sdk 1.0.0 → 1.1.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 +6 -1
- package/dist/cjs/error-wrappers.js +80 -0
- package/dist/cjs/error-wrappers.js.map +1 -0
- package/dist/cjs/internals/error-wrappers.js +25 -0
- package/dist/cjs/internals/error-wrappers.js.map +1 -0
- package/dist/cjs/internals/index.js +1 -0
- package/dist/cjs/internals/index.js.map +1 -1
- package/dist/esm/error-wrappers.js +128 -0
- package/dist/esm/error-wrappers.js.map +1 -0
- package/dist/esm/internals/error-wrappers.js +25 -0
- package/dist/esm/internals/error-wrappers.js.map +1 -0
- package/dist/esm/internals/index.js +1 -0
- package/dist/esm/internals/index.js.map +1 -1
- package/dist/types/error-wrappers.d.ts +413 -0
- package/dist/types/internals/error-wrappers.d.ts +33 -0
- package/dist/types/internals/index.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,9 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.1.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add Snap error wrappers of JSON-RPC errors ([#1924](https://github.com/MetaMask/snaps/pull/1924))
|
|
12
|
+
|
|
9
13
|
## [1.0.0]
|
|
10
14
|
### Added
|
|
11
15
|
- Initial release of this package.
|
|
12
16
|
|
|
13
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.
|
|
17
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.1.0...HEAD
|
|
18
|
+
[1.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.0.0...@metamask/snaps-sdk@1.1.0
|
|
14
19
|
[1.0.0]: https://github.com/MetaMask/snaps/releases/tag/@metamask/snaps-sdk@1.0.0
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
InternalError: function() {
|
|
13
|
+
return InternalError;
|
|
14
|
+
},
|
|
15
|
+
InvalidInputError: function() {
|
|
16
|
+
return InvalidInputError;
|
|
17
|
+
},
|
|
18
|
+
InvalidParamsError: function() {
|
|
19
|
+
return InvalidParamsError;
|
|
20
|
+
},
|
|
21
|
+
InvalidRequestError: function() {
|
|
22
|
+
return InvalidRequestError;
|
|
23
|
+
},
|
|
24
|
+
LimitExceededError: function() {
|
|
25
|
+
return LimitExceededError;
|
|
26
|
+
},
|
|
27
|
+
MethodNotFoundError: function() {
|
|
28
|
+
return MethodNotFoundError;
|
|
29
|
+
},
|
|
30
|
+
MethodNotSupportedError: function() {
|
|
31
|
+
return MethodNotSupportedError;
|
|
32
|
+
},
|
|
33
|
+
ParseError: function() {
|
|
34
|
+
return ParseError;
|
|
35
|
+
},
|
|
36
|
+
ResourceNotFoundError: function() {
|
|
37
|
+
return ResourceNotFoundError;
|
|
38
|
+
},
|
|
39
|
+
ResourceUnavailableError: function() {
|
|
40
|
+
return ResourceUnavailableError;
|
|
41
|
+
},
|
|
42
|
+
TransactionRejected: function() {
|
|
43
|
+
return TransactionRejected;
|
|
44
|
+
},
|
|
45
|
+
ChainDisconnectedError: function() {
|
|
46
|
+
return ChainDisconnectedError;
|
|
47
|
+
},
|
|
48
|
+
DisconnectedError: function() {
|
|
49
|
+
return DisconnectedError;
|
|
50
|
+
},
|
|
51
|
+
UnauthorizedError: function() {
|
|
52
|
+
return UnauthorizedError;
|
|
53
|
+
},
|
|
54
|
+
UnsupportedMethodError: function() {
|
|
55
|
+
return UnsupportedMethodError;
|
|
56
|
+
},
|
|
57
|
+
UserRejectedRequestError: function() {
|
|
58
|
+
return UserRejectedRequestError;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const _rpcerrors = require("@metamask/rpc-errors");
|
|
62
|
+
const _internals = require("./internals");
|
|
63
|
+
const InternalError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.internal);
|
|
64
|
+
const InvalidInputError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.invalidInput);
|
|
65
|
+
const InvalidParamsError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.invalidParams);
|
|
66
|
+
const InvalidRequestError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.invalidRequest);
|
|
67
|
+
const LimitExceededError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.limitExceeded);
|
|
68
|
+
const MethodNotFoundError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.methodNotFound);
|
|
69
|
+
const MethodNotSupportedError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.methodNotSupported);
|
|
70
|
+
const ParseError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.parse);
|
|
71
|
+
const ResourceNotFoundError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.resourceNotFound);
|
|
72
|
+
const ResourceUnavailableError = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.resourceUnavailable);
|
|
73
|
+
const TransactionRejected = (0, _internals.createSnapError)(_rpcerrors.rpcErrors.transactionRejected);
|
|
74
|
+
const ChainDisconnectedError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.chainDisconnected);
|
|
75
|
+
const DisconnectedError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.disconnected);
|
|
76
|
+
const UnauthorizedError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.unauthorized);
|
|
77
|
+
const UnsupportedMethodError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.unsupportedMethod);
|
|
78
|
+
const UserRejectedRequestError = (0, _internals.createSnapError)(_rpcerrors.providerErrors.userRejectedRequest);
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=error-wrappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/error-wrappers.ts"],"sourcesContent":["import { providerErrors, rpcErrors } from '@metamask/rpc-errors';\n\nimport { createSnapError } from './internals';\n\n/**\n * A JSON-RPC 2.0 Internal (-32603) error.\n *\n * This can be thrown by a Snap to indicate that an internal error occurred,\n * without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InternalError = createSnapError(rpcErrors.internal);\n\n/**\n * An Ethereum JSON-RPC Invalid Input (-32000) error.\n *\n * This can be thrown by a Snap to indicate that the input to a method is\n * invalid, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const InvalidInputError = createSnapError(rpcErrors.invalidInput);\n\n/**\n * A JSON-RPC 2.0 Invalid Params (-32602) error.\n *\n * This can be thrown by a Snap to indicate that the parameters to a method are\n * invalid, without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InvalidParamsError = createSnapError(rpcErrors.invalidParams);\n\n/**\n * A JSON-RPC 2.0 Invalid Request (-32600) error.\n *\n * This can be thrown by a Snap to indicate that the request is invalid, without\n * crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InvalidRequestError = createSnapError(rpcErrors.invalidRequest);\n\n/**\n * An Ethereum JSON-RPC Limit Exceeded (-32005) error.\n *\n * This can be thrown by a Snap to indicate that a limit has been exceeded,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const LimitExceededError = createSnapError(rpcErrors.limitExceeded);\n\n/**\n * An Ethereum JSON-RPC Method Not Found (-32601) error.\n *\n * This can be thrown by a Snap to indicate that a method does not exist,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const MethodNotFoundError = createSnapError(rpcErrors.methodNotFound);\n\n/**\n * An Ethereum JSON-RPC Method Not Supported (-32004) error.\n *\n * This can be thrown by a Snap to indicate that a method is not supported,\n * without crashing the Snap.\n */\nexport const MethodNotSupportedError = createSnapError(\n rpcErrors.methodNotSupported,\n);\n\n/**\n * A JSON-RPC 2.0 Parse (-32700) error.\n *\n * This can be thrown by a Snap to indicate that a request is not valid JSON,\n * without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const ParseError = createSnapError(rpcErrors.parse);\n\n/**\n * An Ethereum JSON-RPC Resource Not Found (-32001) error.\n *\n * This can be thrown by a Snap to indicate that a resource does not exist,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const ResourceNotFoundError = createSnapError(\n rpcErrors.resourceNotFound,\n);\n\n/**\n * An Ethereum JSON-RPC Resource Unavailable (-32002) error.\n *\n * This can be thrown by a Snap to indicate that a resource is unavailable,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const ResourceUnavailableError = createSnapError(\n rpcErrors.resourceUnavailable,\n);\n\n/**\n * An Ethereum JSON-RPC Transaction Rejected (-32003) error.\n *\n * This can be thrown by a Snap to indicate that a transaction was rejected,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const TransactionRejected = createSnapError(\n rpcErrors.transactionRejected,\n);\n\n/**\n * An Ethereum Provider Chain Disconnected (4901) error.\n *\n * This can be thrown by a Snap to indicate that the provider is disconnected\n * from the requested chain, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const ChainDisconnectedError = createSnapError(\n providerErrors.chainDisconnected,\n);\n\n/**\n * An Ethereum Provider Disconnected (4900) error.\n *\n * This can be thrown by a Snap to indicate that the provider is disconnected,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const DisconnectedError = createSnapError(providerErrors.disconnected);\n\n/**\n * An Ethereum Provider Unauthorized (4100) error.\n *\n * This can be thrown by a Snap to indicate that the requested method / account\n * is not authorized by the user, without crashing the Snap.\n */\nexport const UnauthorizedError = createSnapError(providerErrors.unauthorized);\n\n/**\n * An Ethereum Provider Unsupported Method (4200) error.\n *\n * This can be thrown by a Snap to indicate that the requested method is not\n * supported by the provider, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const UnsupportedMethodError = createSnapError(\n providerErrors.unsupportedMethod,\n);\n\n/**\n * An Ethereum Provider User Rejected Request (4001) error.\n *\n * This can be thrown by a Snap to indicate that the user rejected the request,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const UserRejectedRequestError = createSnapError(\n providerErrors.userRejectedRequest,\n);\n"],"names":["InternalError","InvalidInputError","InvalidParamsError","InvalidRequestError","LimitExceededError","MethodNotFoundError","MethodNotSupportedError","ParseError","ResourceNotFoundError","ResourceUnavailableError","TransactionRejected","ChainDisconnectedError","DisconnectedError","UnauthorizedError","UnsupportedMethodError","UserRejectedRequestError","createSnapError","rpcErrors","internal","invalidInput","invalidParams","invalidRequest","limitExceeded","methodNotFound","methodNotSupported","parse","resourceNotFound","resourceUnavailable","transactionRejected","providerErrors","chainDisconnected","disconnected","unauthorized","unsupportedMethod","userRejectedRequest"],"mappings":";;;;;;;;;;;IAYaA,aAAa;eAAbA;;IAUAC,iBAAiB;eAAjBA;;IAUAC,kBAAkB;eAAlBA;;IAUAC,mBAAmB;eAAnBA;;IAUAC,kBAAkB;eAAlBA;;IAUAC,mBAAmB;eAAnBA;;IAQAC,uBAAuB;eAAvBA;;IAYAC,UAAU;eAAVA;;IAUAC,qBAAqB;eAArBA;;IAYAC,wBAAwB;eAAxBA;;IAYAC,mBAAmB;eAAnBA;;IAYAC,sBAAsB;eAAtBA;;IAYAC,iBAAiB;eAAjBA;;IAQAC,iBAAiB;eAAjBA;;IAUAC,sBAAsB;eAAtBA;;IAYAC,wBAAwB;eAAxBA;;;2BA1K6B;2BAEV;AAUzB,MAAMf,gBAAgBgB,IAAAA,0BAAe,EAACC,oBAAS,CAACC,QAAQ;AAUxD,MAAMjB,oBAAoBe,IAAAA,0BAAe,EAACC,oBAAS,CAACE,YAAY;AAUhE,MAAMjB,qBAAqBc,IAAAA,0BAAe,EAACC,oBAAS,CAACG,aAAa;AAUlE,MAAMjB,sBAAsBa,IAAAA,0BAAe,EAACC,oBAAS,CAACI,cAAc;AAUpE,MAAMjB,qBAAqBY,IAAAA,0BAAe,EAACC,oBAAS,CAACK,aAAa;AAUlE,MAAMjB,sBAAsBW,IAAAA,0BAAe,EAACC,oBAAS,CAACM,cAAc;AAQpE,MAAMjB,0BAA0BU,IAAAA,0BAAe,EACpDC,oBAAS,CAACO,kBAAkB;AAWvB,MAAMjB,aAAaS,IAAAA,0BAAe,EAACC,oBAAS,CAACQ,KAAK;AAUlD,MAAMjB,wBAAwBQ,IAAAA,0BAAe,EAClDC,oBAAS,CAACS,gBAAgB;AAWrB,MAAMjB,2BAA2BO,IAAAA,0BAAe,EACrDC,oBAAS,CAACU,mBAAmB;AAWxB,MAAMjB,sBAAsBM,IAAAA,0BAAe,EAChDC,oBAAS,CAACW,mBAAmB;AAWxB,MAAMjB,yBAAyBK,IAAAA,0BAAe,EACnDa,yBAAc,CAACC,iBAAiB;AAW3B,MAAMlB,oBAAoBI,IAAAA,0BAAe,EAACa,yBAAc,CAACE,YAAY;AAQrE,MAAMlB,oBAAoBG,IAAAA,0BAAe,EAACa,yBAAc,CAACG,YAAY;AAUrE,MAAMlB,yBAAyBE,IAAAA,0BAAe,EACnDa,yBAAc,CAACI,iBAAiB;AAW3B,MAAMlB,2BAA2BC,IAAAA,0BAAe,EACrDa,yBAAc,CAACK,mBAAmB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createSnapError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createSnapError;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _errors = require("../errors");
|
|
12
|
+
function createSnapError(fn) {
|
|
13
|
+
return class SnapJsonRpcError extends _errors.SnapError {
|
|
14
|
+
constructor(message, data){
|
|
15
|
+
const error = fn(message);
|
|
16
|
+
super({
|
|
17
|
+
code: error.code,
|
|
18
|
+
message: error.message,
|
|
19
|
+
data
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=error-wrappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/error-wrappers.ts"],"sourcesContent":["import type { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\n\nimport { SnapError } from '../errors';\n\nexport type JsonRpcErrorFunction = typeof rpcErrors.parse;\n\n/**\n * Create a `SnapError` class from an error function from\n * `@metamask/rpc-errors`. This is useful for creating custom error classes\n * which can be thrown by a Snap.\n *\n * The created class will inherit the message, code, and data properties from\n * the error function.\n *\n * @param fn - The error function to create the class from.\n * @returns The created `SnapError` class.\n */\nexport function createSnapError(fn: JsonRpcErrorFunction) {\n return class SnapJsonRpcError extends SnapError {\n constructor(message?: string, data?: Record<string, Json>) {\n const error = fn(message);\n\n super({\n code: error.code,\n message: error.message,\n data,\n });\n }\n };\n}\n"],"names":["createSnapError","fn","SnapJsonRpcError","SnapError","constructor","message","data","error","code"],"mappings":";;;;+BAkBgBA;;;eAAAA;;;wBAfU;AAenB,SAASA,gBAAgBC,EAAwB;IACtD,OAAO,MAAMC,yBAAyBC,iBAAS;QAC7CC,YAAYC,OAAgB,EAAEC,IAA2B,CAAE;YACzD,MAAMC,QAAQN,GAAGI;YAEjB,KAAK,CAAC;gBACJG,MAAMD,MAAMC,IAAI;gBAChBH,SAASE,MAAMF,OAAO;gBACtBC;YACF;QACF;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './errors';\nexport * from './helpers';\n"],"names":[],"mappings":";;;;qBAAc;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './error-wrappers';\nexport * from './errors';\nexport * from './helpers';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { providerErrors, rpcErrors } from '@metamask/rpc-errors';
|
|
2
|
+
import { createSnapError } from './internals';
|
|
3
|
+
/**
|
|
4
|
+
* A JSON-RPC 2.0 Internal (-32603) error.
|
|
5
|
+
*
|
|
6
|
+
* This can be thrown by a Snap to indicate that an internal error occurred,
|
|
7
|
+
* without crashing the Snap.
|
|
8
|
+
*
|
|
9
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
10
|
+
*/ export const InternalError = createSnapError(rpcErrors.internal);
|
|
11
|
+
/**
|
|
12
|
+
* An Ethereum JSON-RPC Invalid Input (-32000) error.
|
|
13
|
+
*
|
|
14
|
+
* This can be thrown by a Snap to indicate that the input to a method is
|
|
15
|
+
* invalid, without crashing the Snap.
|
|
16
|
+
*
|
|
17
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
18
|
+
*/ export const InvalidInputError = createSnapError(rpcErrors.invalidInput);
|
|
19
|
+
/**
|
|
20
|
+
* A JSON-RPC 2.0 Invalid Params (-32602) error.
|
|
21
|
+
*
|
|
22
|
+
* This can be thrown by a Snap to indicate that the parameters to a method are
|
|
23
|
+
* invalid, without crashing the Snap.
|
|
24
|
+
*
|
|
25
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
26
|
+
*/ export const InvalidParamsError = createSnapError(rpcErrors.invalidParams);
|
|
27
|
+
/**
|
|
28
|
+
* A JSON-RPC 2.0 Invalid Request (-32600) error.
|
|
29
|
+
*
|
|
30
|
+
* This can be thrown by a Snap to indicate that the request is invalid, without
|
|
31
|
+
* crashing the Snap.
|
|
32
|
+
*
|
|
33
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
34
|
+
*/ export const InvalidRequestError = createSnapError(rpcErrors.invalidRequest);
|
|
35
|
+
/**
|
|
36
|
+
* An Ethereum JSON-RPC Limit Exceeded (-32005) error.
|
|
37
|
+
*
|
|
38
|
+
* This can be thrown by a Snap to indicate that a limit has been exceeded,
|
|
39
|
+
* without crashing the Snap.
|
|
40
|
+
*
|
|
41
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
42
|
+
*/ export const LimitExceededError = createSnapError(rpcErrors.limitExceeded);
|
|
43
|
+
/**
|
|
44
|
+
* An Ethereum JSON-RPC Method Not Found (-32601) error.
|
|
45
|
+
*
|
|
46
|
+
* This can be thrown by a Snap to indicate that a method does not exist,
|
|
47
|
+
* without crashing the Snap.
|
|
48
|
+
*
|
|
49
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
50
|
+
*/ export const MethodNotFoundError = createSnapError(rpcErrors.methodNotFound);
|
|
51
|
+
/**
|
|
52
|
+
* An Ethereum JSON-RPC Method Not Supported (-32004) error.
|
|
53
|
+
*
|
|
54
|
+
* This can be thrown by a Snap to indicate that a method is not supported,
|
|
55
|
+
* without crashing the Snap.
|
|
56
|
+
*/ export const MethodNotSupportedError = createSnapError(rpcErrors.methodNotSupported);
|
|
57
|
+
/**
|
|
58
|
+
* A JSON-RPC 2.0 Parse (-32700) error.
|
|
59
|
+
*
|
|
60
|
+
* This can be thrown by a Snap to indicate that a request is not valid JSON,
|
|
61
|
+
* without crashing the Snap.
|
|
62
|
+
*
|
|
63
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
64
|
+
*/ export const ParseError = createSnapError(rpcErrors.parse);
|
|
65
|
+
/**
|
|
66
|
+
* An Ethereum JSON-RPC Resource Not Found (-32001) error.
|
|
67
|
+
*
|
|
68
|
+
* This can be thrown by a Snap to indicate that a resource does not exist,
|
|
69
|
+
* without crashing the Snap.
|
|
70
|
+
*
|
|
71
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
72
|
+
*/ export const ResourceNotFoundError = createSnapError(rpcErrors.resourceNotFound);
|
|
73
|
+
/**
|
|
74
|
+
* An Ethereum JSON-RPC Resource Unavailable (-32002) error.
|
|
75
|
+
*
|
|
76
|
+
* This can be thrown by a Snap to indicate that a resource is unavailable,
|
|
77
|
+
* without crashing the Snap.
|
|
78
|
+
*
|
|
79
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
80
|
+
*/ export const ResourceUnavailableError = createSnapError(rpcErrors.resourceUnavailable);
|
|
81
|
+
/**
|
|
82
|
+
* An Ethereum JSON-RPC Transaction Rejected (-32003) error.
|
|
83
|
+
*
|
|
84
|
+
* This can be thrown by a Snap to indicate that a transaction was rejected,
|
|
85
|
+
* without crashing the Snap.
|
|
86
|
+
*
|
|
87
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
88
|
+
*/ export const TransactionRejected = createSnapError(rpcErrors.transactionRejected);
|
|
89
|
+
/**
|
|
90
|
+
* An Ethereum Provider Chain Disconnected (4901) error.
|
|
91
|
+
*
|
|
92
|
+
* This can be thrown by a Snap to indicate that the provider is disconnected
|
|
93
|
+
* from the requested chain, without crashing the Snap.
|
|
94
|
+
*
|
|
95
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
96
|
+
*/ export const ChainDisconnectedError = createSnapError(providerErrors.chainDisconnected);
|
|
97
|
+
/**
|
|
98
|
+
* An Ethereum Provider Disconnected (4900) error.
|
|
99
|
+
*
|
|
100
|
+
* This can be thrown by a Snap to indicate that the provider is disconnected,
|
|
101
|
+
* without crashing the Snap.
|
|
102
|
+
*
|
|
103
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
104
|
+
*/ export const DisconnectedError = createSnapError(providerErrors.disconnected);
|
|
105
|
+
/**
|
|
106
|
+
* An Ethereum Provider Unauthorized (4100) error.
|
|
107
|
+
*
|
|
108
|
+
* This can be thrown by a Snap to indicate that the requested method / account
|
|
109
|
+
* is not authorized by the user, without crashing the Snap.
|
|
110
|
+
*/ export const UnauthorizedError = createSnapError(providerErrors.unauthorized);
|
|
111
|
+
/**
|
|
112
|
+
* An Ethereum Provider Unsupported Method (4200) error.
|
|
113
|
+
*
|
|
114
|
+
* This can be thrown by a Snap to indicate that the requested method is not
|
|
115
|
+
* supported by the provider, without crashing the Snap.
|
|
116
|
+
*
|
|
117
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
118
|
+
*/ export const UnsupportedMethodError = createSnapError(providerErrors.unsupportedMethod);
|
|
119
|
+
/**
|
|
120
|
+
* An Ethereum Provider User Rejected Request (4001) error.
|
|
121
|
+
*
|
|
122
|
+
* This can be thrown by a Snap to indicate that the user rejected the request,
|
|
123
|
+
* without crashing the Snap.
|
|
124
|
+
*
|
|
125
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
126
|
+
*/ export const UserRejectedRequestError = createSnapError(providerErrors.userRejectedRequest);
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=error-wrappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/error-wrappers.ts"],"sourcesContent":["import { providerErrors, rpcErrors } from '@metamask/rpc-errors';\n\nimport { createSnapError } from './internals';\n\n/**\n * A JSON-RPC 2.0 Internal (-32603) error.\n *\n * This can be thrown by a Snap to indicate that an internal error occurred,\n * without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InternalError = createSnapError(rpcErrors.internal);\n\n/**\n * An Ethereum JSON-RPC Invalid Input (-32000) error.\n *\n * This can be thrown by a Snap to indicate that the input to a method is\n * invalid, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const InvalidInputError = createSnapError(rpcErrors.invalidInput);\n\n/**\n * A JSON-RPC 2.0 Invalid Params (-32602) error.\n *\n * This can be thrown by a Snap to indicate that the parameters to a method are\n * invalid, without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InvalidParamsError = createSnapError(rpcErrors.invalidParams);\n\n/**\n * A JSON-RPC 2.0 Invalid Request (-32600) error.\n *\n * This can be thrown by a Snap to indicate that the request is invalid, without\n * crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const InvalidRequestError = createSnapError(rpcErrors.invalidRequest);\n\n/**\n * An Ethereum JSON-RPC Limit Exceeded (-32005) error.\n *\n * This can be thrown by a Snap to indicate that a limit has been exceeded,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const LimitExceededError = createSnapError(rpcErrors.limitExceeded);\n\n/**\n * An Ethereum JSON-RPC Method Not Found (-32601) error.\n *\n * This can be thrown by a Snap to indicate that a method does not exist,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const MethodNotFoundError = createSnapError(rpcErrors.methodNotFound);\n\n/**\n * An Ethereum JSON-RPC Method Not Supported (-32004) error.\n *\n * This can be thrown by a Snap to indicate that a method is not supported,\n * without crashing the Snap.\n */\nexport const MethodNotSupportedError = createSnapError(\n rpcErrors.methodNotSupported,\n);\n\n/**\n * A JSON-RPC 2.0 Parse (-32700) error.\n *\n * This can be thrown by a Snap to indicate that a request is not valid JSON,\n * without crashing the Snap.\n *\n * @see https://www.jsonrpc.org/specification#error_object\n */\nexport const ParseError = createSnapError(rpcErrors.parse);\n\n/**\n * An Ethereum JSON-RPC Resource Not Found (-32001) error.\n *\n * This can be thrown by a Snap to indicate that a resource does not exist,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const ResourceNotFoundError = createSnapError(\n rpcErrors.resourceNotFound,\n);\n\n/**\n * An Ethereum JSON-RPC Resource Unavailable (-32002) error.\n *\n * This can be thrown by a Snap to indicate that a resource is unavailable,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const ResourceUnavailableError = createSnapError(\n rpcErrors.resourceUnavailable,\n);\n\n/**\n * An Ethereum JSON-RPC Transaction Rejected (-32003) error.\n *\n * This can be thrown by a Snap to indicate that a transaction was rejected,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1474#error-codes\n */\nexport const TransactionRejected = createSnapError(\n rpcErrors.transactionRejected,\n);\n\n/**\n * An Ethereum Provider Chain Disconnected (4901) error.\n *\n * This can be thrown by a Snap to indicate that the provider is disconnected\n * from the requested chain, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const ChainDisconnectedError = createSnapError(\n providerErrors.chainDisconnected,\n);\n\n/**\n * An Ethereum Provider Disconnected (4900) error.\n *\n * This can be thrown by a Snap to indicate that the provider is disconnected,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const DisconnectedError = createSnapError(providerErrors.disconnected);\n\n/**\n * An Ethereum Provider Unauthorized (4100) error.\n *\n * This can be thrown by a Snap to indicate that the requested method / account\n * is not authorized by the user, without crashing the Snap.\n */\nexport const UnauthorizedError = createSnapError(providerErrors.unauthorized);\n\n/**\n * An Ethereum Provider Unsupported Method (4200) error.\n *\n * This can be thrown by a Snap to indicate that the requested method is not\n * supported by the provider, without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const UnsupportedMethodError = createSnapError(\n providerErrors.unsupportedMethod,\n);\n\n/**\n * An Ethereum Provider User Rejected Request (4001) error.\n *\n * This can be thrown by a Snap to indicate that the user rejected the request,\n * without crashing the Snap.\n *\n * @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors\n */\nexport const UserRejectedRequestError = createSnapError(\n providerErrors.userRejectedRequest,\n);\n"],"names":["providerErrors","rpcErrors","createSnapError","InternalError","internal","InvalidInputError","invalidInput","InvalidParamsError","invalidParams","InvalidRequestError","invalidRequest","LimitExceededError","limitExceeded","MethodNotFoundError","methodNotFound","MethodNotSupportedError","methodNotSupported","ParseError","parse","ResourceNotFoundError","resourceNotFound","ResourceUnavailableError","resourceUnavailable","TransactionRejected","transactionRejected","ChainDisconnectedError","chainDisconnected","DisconnectedError","disconnected","UnauthorizedError","unauthorized","UnsupportedMethodError","unsupportedMethod","UserRejectedRequestError","userRejectedRequest"],"mappings":"AAAA,SAASA,cAAc,EAAEC,SAAS,QAAQ,uBAAuB;AAEjE,SAASC,eAAe,QAAQ,cAAc;AAE9C;;;;;;;CAOC,GACD,OAAO,MAAMC,gBAAgBD,gBAAgBD,UAAUG,QAAQ,EAAE;AAEjE;;;;;;;CAOC,GACD,OAAO,MAAMC,oBAAoBH,gBAAgBD,UAAUK,YAAY,EAAE;AAEzE;;;;;;;CAOC,GACD,OAAO,MAAMC,qBAAqBL,gBAAgBD,UAAUO,aAAa,EAAE;AAE3E;;;;;;;CAOC,GACD,OAAO,MAAMC,sBAAsBP,gBAAgBD,UAAUS,cAAc,EAAE;AAE7E;;;;;;;CAOC,GACD,OAAO,MAAMC,qBAAqBT,gBAAgBD,UAAUW,aAAa,EAAE;AAE3E;;;;;;;CAOC,GACD,OAAO,MAAMC,sBAAsBX,gBAAgBD,UAAUa,cAAc,EAAE;AAE7E;;;;;CAKC,GACD,OAAO,MAAMC,0BAA0Bb,gBACrCD,UAAUe,kBAAkB,EAC5B;AAEF;;;;;;;CAOC,GACD,OAAO,MAAMC,aAAaf,gBAAgBD,UAAUiB,KAAK,EAAE;AAE3D;;;;;;;CAOC,GACD,OAAO,MAAMC,wBAAwBjB,gBACnCD,UAAUmB,gBAAgB,EAC1B;AAEF;;;;;;;CAOC,GACD,OAAO,MAAMC,2BAA2BnB,gBACtCD,UAAUqB,mBAAmB,EAC7B;AAEF;;;;;;;CAOC,GACD,OAAO,MAAMC,sBAAsBrB,gBACjCD,UAAUuB,mBAAmB,EAC7B;AAEF;;;;;;;CAOC,GACD,OAAO,MAAMC,yBAAyBvB,gBACpCF,eAAe0B,iBAAiB,EAChC;AAEF;;;;;;;CAOC,GACD,OAAO,MAAMC,oBAAoBzB,gBAAgBF,eAAe4B,YAAY,EAAE;AAE9E;;;;;CAKC,GACD,OAAO,MAAMC,oBAAoB3B,gBAAgBF,eAAe8B,YAAY,EAAE;AAE9E;;;;;;;CAOC,GACD,OAAO,MAAMC,yBAAyB7B,gBACpCF,eAAegC,iBAAiB,EAChC;AAEF;;;;;;;CAOC,GACD,OAAO,MAAMC,2BAA2B/B,gBACtCF,eAAekC,mBAAmB,EAClC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SnapError } from '../errors';
|
|
2
|
+
/**
|
|
3
|
+
* Create a `SnapError` class from an error function from
|
|
4
|
+
* `@metamask/rpc-errors`. This is useful for creating custom error classes
|
|
5
|
+
* which can be thrown by a Snap.
|
|
6
|
+
*
|
|
7
|
+
* The created class will inherit the message, code, and data properties from
|
|
8
|
+
* the error function.
|
|
9
|
+
*
|
|
10
|
+
* @param fn - The error function to create the class from.
|
|
11
|
+
* @returns The created `SnapError` class.
|
|
12
|
+
*/ export function createSnapError(fn) {
|
|
13
|
+
return class SnapJsonRpcError extends SnapError {
|
|
14
|
+
constructor(message, data){
|
|
15
|
+
const error = fn(message);
|
|
16
|
+
super({
|
|
17
|
+
code: error.code,
|
|
18
|
+
message: error.message,
|
|
19
|
+
data
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=error-wrappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/error-wrappers.ts"],"sourcesContent":["import type { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\n\nimport { SnapError } from '../errors';\n\nexport type JsonRpcErrorFunction = typeof rpcErrors.parse;\n\n/**\n * Create a `SnapError` class from an error function from\n * `@metamask/rpc-errors`. This is useful for creating custom error classes\n * which can be thrown by a Snap.\n *\n * The created class will inherit the message, code, and data properties from\n * the error function.\n *\n * @param fn - The error function to create the class from.\n * @returns The created `SnapError` class.\n */\nexport function createSnapError(fn: JsonRpcErrorFunction) {\n return class SnapJsonRpcError extends SnapError {\n constructor(message?: string, data?: Record<string, Json>) {\n const error = fn(message);\n\n super({\n code: error.code,\n message: error.message,\n data,\n });\n }\n };\n}\n"],"names":["SnapError","createSnapError","fn","SnapJsonRpcError","constructor","message","data","error","code"],"mappings":"AAGA,SAASA,SAAS,QAAQ,YAAY;AAItC;;;;;;;;;;CAUC,GACD,OAAO,SAASC,gBAAgBC,EAAwB;IACtD,OAAO,MAAMC,yBAAyBH;QACpCI,YAAYC,OAAgB,EAAEC,IAA2B,CAAE;YACzD,MAAMC,QAAQL,GAAGG;YAEjB,KAAK,CAAC;gBACJG,MAAMD,MAAMC,IAAI;gBAChBH,SAASE,MAAMF,OAAO;gBACtBC;YACF;QACF;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './errors';\nexport * from './helpers';\n"],"names":[],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,YAAY"}
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './error-wrappers';\nexport * from './errors';\nexport * from './helpers';\n"],"names":[],"mappings":"AAAA,cAAc,mBAAmB;AACjC,cAAc,WAAW;AACzB,cAAc,YAAY"}
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* A JSON-RPC 2.0 Internal (-32603) error.
|
|
4
|
+
*
|
|
5
|
+
* This can be thrown by a Snap to indicate that an internal error occurred,
|
|
6
|
+
* without crashing the Snap.
|
|
7
|
+
*
|
|
8
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
9
|
+
*/
|
|
10
|
+
export declare const InternalError: {
|
|
11
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
12
|
+
readonly "__#3@#code": number;
|
|
13
|
+
readonly "__#3@#message": string;
|
|
14
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
15
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly code: number;
|
|
18
|
+
readonly message: string;
|
|
19
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
20
|
+
readonly stack: string | undefined;
|
|
21
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
22
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
23
|
+
};
|
|
24
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
25
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
26
|
+
stackTraceLimit: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* An Ethereum JSON-RPC Invalid Input (-32000) error.
|
|
30
|
+
*
|
|
31
|
+
* This can be thrown by a Snap to indicate that the input to a method is
|
|
32
|
+
* invalid, without crashing the Snap.
|
|
33
|
+
*
|
|
34
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
35
|
+
*/
|
|
36
|
+
export declare const InvalidInputError: {
|
|
37
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
38
|
+
readonly "__#3@#code": number;
|
|
39
|
+
readonly "__#3@#message": string;
|
|
40
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
41
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly code: number;
|
|
44
|
+
readonly message: string;
|
|
45
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
46
|
+
readonly stack: string | undefined;
|
|
47
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
48
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
49
|
+
};
|
|
50
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
51
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
52
|
+
stackTraceLimit: number;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* A JSON-RPC 2.0 Invalid Params (-32602) error.
|
|
56
|
+
*
|
|
57
|
+
* This can be thrown by a Snap to indicate that the parameters to a method are
|
|
58
|
+
* invalid, without crashing the Snap.
|
|
59
|
+
*
|
|
60
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
61
|
+
*/
|
|
62
|
+
export declare const InvalidParamsError: {
|
|
63
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
64
|
+
readonly "__#3@#code": number;
|
|
65
|
+
readonly "__#3@#message": string;
|
|
66
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
67
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
68
|
+
readonly name: string;
|
|
69
|
+
readonly code: number;
|
|
70
|
+
readonly message: string;
|
|
71
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
72
|
+
readonly stack: string | undefined;
|
|
73
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
74
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
75
|
+
};
|
|
76
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
77
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
78
|
+
stackTraceLimit: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* A JSON-RPC 2.0 Invalid Request (-32600) error.
|
|
82
|
+
*
|
|
83
|
+
* This can be thrown by a Snap to indicate that the request is invalid, without
|
|
84
|
+
* crashing the Snap.
|
|
85
|
+
*
|
|
86
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
87
|
+
*/
|
|
88
|
+
export declare const InvalidRequestError: {
|
|
89
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
90
|
+
readonly "__#3@#code": number;
|
|
91
|
+
readonly "__#3@#message": string;
|
|
92
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
93
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly code: number;
|
|
96
|
+
readonly message: string;
|
|
97
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
98
|
+
readonly stack: string | undefined;
|
|
99
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
100
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
101
|
+
};
|
|
102
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
103
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
104
|
+
stackTraceLimit: number;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* An Ethereum JSON-RPC Limit Exceeded (-32005) error.
|
|
108
|
+
*
|
|
109
|
+
* This can be thrown by a Snap to indicate that a limit has been exceeded,
|
|
110
|
+
* without crashing the Snap.
|
|
111
|
+
*
|
|
112
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
113
|
+
*/
|
|
114
|
+
export declare const LimitExceededError: {
|
|
115
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
116
|
+
readonly "__#3@#code": number;
|
|
117
|
+
readonly "__#3@#message": string;
|
|
118
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
119
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
120
|
+
readonly name: string;
|
|
121
|
+
readonly code: number;
|
|
122
|
+
readonly message: string;
|
|
123
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
124
|
+
readonly stack: string | undefined;
|
|
125
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
126
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
127
|
+
};
|
|
128
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
129
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
130
|
+
stackTraceLimit: number;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* An Ethereum JSON-RPC Method Not Found (-32601) error.
|
|
134
|
+
*
|
|
135
|
+
* This can be thrown by a Snap to indicate that a method does not exist,
|
|
136
|
+
* without crashing the Snap.
|
|
137
|
+
*
|
|
138
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
139
|
+
*/
|
|
140
|
+
export declare const MethodNotFoundError: {
|
|
141
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
142
|
+
readonly "__#3@#code": number;
|
|
143
|
+
readonly "__#3@#message": string;
|
|
144
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
145
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
146
|
+
readonly name: string;
|
|
147
|
+
readonly code: number;
|
|
148
|
+
readonly message: string;
|
|
149
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
150
|
+
readonly stack: string | undefined;
|
|
151
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
152
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
153
|
+
};
|
|
154
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
155
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
156
|
+
stackTraceLimit: number;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* An Ethereum JSON-RPC Method Not Supported (-32004) error.
|
|
160
|
+
*
|
|
161
|
+
* This can be thrown by a Snap to indicate that a method is not supported,
|
|
162
|
+
* without crashing the Snap.
|
|
163
|
+
*/
|
|
164
|
+
export declare const MethodNotSupportedError: {
|
|
165
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
166
|
+
readonly "__#3@#code": number;
|
|
167
|
+
readonly "__#3@#message": string;
|
|
168
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
169
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
170
|
+
readonly name: string;
|
|
171
|
+
readonly code: number;
|
|
172
|
+
readonly message: string;
|
|
173
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
174
|
+
readonly stack: string | undefined;
|
|
175
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
176
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
177
|
+
};
|
|
178
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
179
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
180
|
+
stackTraceLimit: number;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* A JSON-RPC 2.0 Parse (-32700) error.
|
|
184
|
+
*
|
|
185
|
+
* This can be thrown by a Snap to indicate that a request is not valid JSON,
|
|
186
|
+
* without crashing the Snap.
|
|
187
|
+
*
|
|
188
|
+
* @see https://www.jsonrpc.org/specification#error_object
|
|
189
|
+
*/
|
|
190
|
+
export declare const ParseError: {
|
|
191
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
192
|
+
readonly "__#3@#code": number;
|
|
193
|
+
readonly "__#3@#message": string;
|
|
194
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
195
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
196
|
+
readonly name: string;
|
|
197
|
+
readonly code: number;
|
|
198
|
+
readonly message: string;
|
|
199
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
200
|
+
readonly stack: string | undefined;
|
|
201
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
202
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
203
|
+
};
|
|
204
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
205
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
206
|
+
stackTraceLimit: number;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* An Ethereum JSON-RPC Resource Not Found (-32001) error.
|
|
210
|
+
*
|
|
211
|
+
* This can be thrown by a Snap to indicate that a resource does not exist,
|
|
212
|
+
* without crashing the Snap.
|
|
213
|
+
*
|
|
214
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
215
|
+
*/
|
|
216
|
+
export declare const ResourceNotFoundError: {
|
|
217
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
218
|
+
readonly "__#3@#code": number;
|
|
219
|
+
readonly "__#3@#message": string;
|
|
220
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
221
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
222
|
+
readonly name: string;
|
|
223
|
+
readonly code: number;
|
|
224
|
+
readonly message: string;
|
|
225
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
226
|
+
readonly stack: string | undefined;
|
|
227
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
228
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
229
|
+
};
|
|
230
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
231
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
232
|
+
stackTraceLimit: number;
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* An Ethereum JSON-RPC Resource Unavailable (-32002) error.
|
|
236
|
+
*
|
|
237
|
+
* This can be thrown by a Snap to indicate that a resource is unavailable,
|
|
238
|
+
* without crashing the Snap.
|
|
239
|
+
*
|
|
240
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
241
|
+
*/
|
|
242
|
+
export declare const ResourceUnavailableError: {
|
|
243
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
244
|
+
readonly "__#3@#code": number;
|
|
245
|
+
readonly "__#3@#message": string;
|
|
246
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
247
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
248
|
+
readonly name: string;
|
|
249
|
+
readonly code: number;
|
|
250
|
+
readonly message: string;
|
|
251
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
252
|
+
readonly stack: string | undefined;
|
|
253
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
254
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
255
|
+
};
|
|
256
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
257
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
258
|
+
stackTraceLimit: number;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* An Ethereum JSON-RPC Transaction Rejected (-32003) error.
|
|
262
|
+
*
|
|
263
|
+
* This can be thrown by a Snap to indicate that a transaction was rejected,
|
|
264
|
+
* without crashing the Snap.
|
|
265
|
+
*
|
|
266
|
+
* @see https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
|
267
|
+
*/
|
|
268
|
+
export declare const TransactionRejected: {
|
|
269
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
270
|
+
readonly "__#3@#code": number;
|
|
271
|
+
readonly "__#3@#message": string;
|
|
272
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
273
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
274
|
+
readonly name: string;
|
|
275
|
+
readonly code: number;
|
|
276
|
+
readonly message: string;
|
|
277
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
278
|
+
readonly stack: string | undefined;
|
|
279
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
280
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
281
|
+
};
|
|
282
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
283
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
284
|
+
stackTraceLimit: number;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* An Ethereum Provider Chain Disconnected (4901) error.
|
|
288
|
+
*
|
|
289
|
+
* This can be thrown by a Snap to indicate that the provider is disconnected
|
|
290
|
+
* from the requested chain, without crashing the Snap.
|
|
291
|
+
*
|
|
292
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
293
|
+
*/
|
|
294
|
+
export declare const ChainDisconnectedError: {
|
|
295
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
296
|
+
readonly "__#3@#code": number;
|
|
297
|
+
readonly "__#3@#message": string;
|
|
298
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
299
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
300
|
+
readonly name: string;
|
|
301
|
+
readonly code: number;
|
|
302
|
+
readonly message: string;
|
|
303
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
304
|
+
readonly stack: string | undefined;
|
|
305
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
306
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
307
|
+
};
|
|
308
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
309
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
310
|
+
stackTraceLimit: number;
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* An Ethereum Provider Disconnected (4900) error.
|
|
314
|
+
*
|
|
315
|
+
* This can be thrown by a Snap to indicate that the provider is disconnected,
|
|
316
|
+
* without crashing the Snap.
|
|
317
|
+
*
|
|
318
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
319
|
+
*/
|
|
320
|
+
export declare const DisconnectedError: {
|
|
321
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
322
|
+
readonly "__#3@#code": number;
|
|
323
|
+
readonly "__#3@#message": string;
|
|
324
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
325
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
326
|
+
readonly name: string;
|
|
327
|
+
readonly code: number;
|
|
328
|
+
readonly message: string;
|
|
329
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
330
|
+
readonly stack: string | undefined;
|
|
331
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
332
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
333
|
+
};
|
|
334
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
335
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
336
|
+
stackTraceLimit: number;
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* An Ethereum Provider Unauthorized (4100) error.
|
|
340
|
+
*
|
|
341
|
+
* This can be thrown by a Snap to indicate that the requested method / account
|
|
342
|
+
* is not authorized by the user, without crashing the Snap.
|
|
343
|
+
*/
|
|
344
|
+
export declare const UnauthorizedError: {
|
|
345
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
346
|
+
readonly "__#3@#code": number;
|
|
347
|
+
readonly "__#3@#message": string;
|
|
348
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
349
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
350
|
+
readonly name: string;
|
|
351
|
+
readonly code: number;
|
|
352
|
+
readonly message: string;
|
|
353
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
354
|
+
readonly stack: string | undefined;
|
|
355
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
356
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
357
|
+
};
|
|
358
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
359
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
360
|
+
stackTraceLimit: number;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* An Ethereum Provider Unsupported Method (4200) error.
|
|
364
|
+
*
|
|
365
|
+
* This can be thrown by a Snap to indicate that the requested method is not
|
|
366
|
+
* supported by the provider, without crashing the Snap.
|
|
367
|
+
*
|
|
368
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
369
|
+
*/
|
|
370
|
+
export declare const UnsupportedMethodError: {
|
|
371
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
372
|
+
readonly "__#3@#code": number;
|
|
373
|
+
readonly "__#3@#message": string;
|
|
374
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
375
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
376
|
+
readonly name: string;
|
|
377
|
+
readonly code: number;
|
|
378
|
+
readonly message: string;
|
|
379
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
380
|
+
readonly stack: string | undefined;
|
|
381
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
382
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
383
|
+
};
|
|
384
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
385
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
386
|
+
stackTraceLimit: number;
|
|
387
|
+
};
|
|
388
|
+
/**
|
|
389
|
+
* An Ethereum Provider User Rejected Request (4001) error.
|
|
390
|
+
*
|
|
391
|
+
* This can be thrown by a Snap to indicate that the user rejected the request,
|
|
392
|
+
* without crashing the Snap.
|
|
393
|
+
*
|
|
394
|
+
* @see https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
|
395
|
+
*/
|
|
396
|
+
export declare const UserRejectedRequestError: {
|
|
397
|
+
new (message?: string | undefined, data?: Record<string, import("@metamask/utils").Json> | undefined): {
|
|
398
|
+
readonly "__#3@#code": number;
|
|
399
|
+
readonly "__#3@#message": string;
|
|
400
|
+
readonly "__#3@#data": Record<string, import("@metamask/utils").Json>;
|
|
401
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
402
|
+
readonly name: string;
|
|
403
|
+
readonly code: number;
|
|
404
|
+
readonly message: string;
|
|
405
|
+
readonly data: Record<string, import("@metamask/utils").Json>;
|
|
406
|
+
readonly stack: string | undefined;
|
|
407
|
+
toJSON(): import("./errors").SerializedSnapError;
|
|
408
|
+
serialize(): import("./errors").SerializedSnapError;
|
|
409
|
+
};
|
|
410
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
411
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
412
|
+
stackTraceLimit: number;
|
|
413
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { rpcErrors } from '@metamask/rpc-errors';
|
|
3
|
+
import type { Json } from '@metamask/utils';
|
|
4
|
+
export declare type JsonRpcErrorFunction = typeof rpcErrors.parse;
|
|
5
|
+
/**
|
|
6
|
+
* Create a `SnapError` class from an error function from
|
|
7
|
+
* `@metamask/rpc-errors`. This is useful for creating custom error classes
|
|
8
|
+
* which can be thrown by a Snap.
|
|
9
|
+
*
|
|
10
|
+
* The created class will inherit the message, code, and data properties from
|
|
11
|
+
* the error function.
|
|
12
|
+
*
|
|
13
|
+
* @param fn - The error function to create the class from.
|
|
14
|
+
* @returns The created `SnapError` class.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createSnapError(fn: JsonRpcErrorFunction): {
|
|
17
|
+
new (message?: string, data?: Record<string, Json>): {
|
|
18
|
+
readonly "__#3@#code": number;
|
|
19
|
+
readonly "__#3@#message": string;
|
|
20
|
+
readonly "__#3@#data": Record<string, Json>;
|
|
21
|
+
readonly "__#3@#stack"?: string | undefined;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly code: number;
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly data: Record<string, Json>;
|
|
26
|
+
readonly stack: string | undefined;
|
|
27
|
+
toJSON(): import("../errors").SerializedSnapError;
|
|
28
|
+
serialize(): import("../errors").SerializedSnapError;
|
|
29
|
+
};
|
|
30
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
31
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
32
|
+
stackTraceLimit: number;
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/MetaMask/snaps.git"
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@metamask/key-tree": "^9.0.0",
|
|
39
39
|
"@metamask/providers": "^13.0.0",
|
|
40
|
+
"@metamask/rpc-errors": "^6.1.0",
|
|
40
41
|
"@metamask/utils": "^8.1.0",
|
|
41
42
|
"is-svg": "^4.4.0",
|
|
42
43
|
"superstruct": "^1.0.3"
|
|
@@ -48,7 +49,6 @@
|
|
|
48
49
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
49
50
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
50
51
|
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
51
|
-
"@metamask/rpc-errors": "^6.1.0",
|
|
52
52
|
"@swc/cli": "^0.1.62",
|
|
53
53
|
"@swc/core": "1.3.78",
|
|
54
54
|
"@swc/jest": "^0.2.26",
|