@metamask/snaps-utils 0.35.0-flask.1 → 1.0.0-prerelease.1
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 +5 -41
- package/dist/{esm/array.js → array.js} +7 -3
- package/dist/array.js.map +1 -0
- package/dist/{types/caveats.d.ts → caveats.d.ts} +4 -0
- package/dist/caveats.js +35 -0
- package/dist/caveats.js.map +1 -0
- package/dist/checksum.js +42 -0
- package/dist/checksum.js.map +1 -0
- package/dist/cronjob.js +71 -0
- package/dist/cronjob.js.map +1 -0
- package/dist/deep-clone.js +9 -0
- package/dist/deep-clone.js.map +1 -0
- package/dist/{esm/default-endowments.js → default-endowments.js} +6 -3
- package/dist/default-endowments.js.map +1 -0
- package/dist/entropy.js +8 -0
- package/dist/entropy.js.map +1 -0
- package/dist/{cjs/eval-worker.js → eval-worker.js} +21 -22
- package/dist/eval-worker.js.map +1 -0
- package/dist/eval.js +27 -0
- package/dist/eval.js.map +1 -0
- package/dist/{esm/fs.js → fs.js} +56 -33
- package/dist/fs.js.map +1 -0
- package/dist/{types/handlers.d.ts → handlers.d.ts} +42 -5
- package/dist/handlers.js +3 -0
- package/dist/handlers.js.map +1 -0
- package/dist/{types/iframe.d.ts → iframe.d.ts} +2 -3
- package/dist/{esm/iframe.js → iframe.js} +18 -16
- package/dist/iframe.js.map +1 -0
- package/dist/iframe.test.browser.js +15 -0
- package/dist/iframe.test.browser.js.map +1 -0
- package/dist/{types/index.browser.d.ts → index.browser.d.ts} +1 -2
- package/dist/index.browser.js +37 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/{types/index.d.ts → index.d.ts} +1 -2
- package/dist/index.executionenv.js +22 -0
- package/dist/index.executionenv.js.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/json-rpc.js +46 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/json.d.ts +9 -0
- package/dist/json.js +18 -0
- package/dist/json.js.map +1 -0
- package/dist/{esm/logging.js → logging.js} +14 -6
- package/dist/logging.js.map +1 -0
- package/dist/manifest/index.browser.js +18 -0
- package/dist/manifest/index.browser.js.map +1 -0
- package/dist/manifest/index.js +19 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/{esm/manifest → manifest}/manifest.js +113 -98
- package/dist/manifest/manifest.js.map +1 -0
- package/dist/{types/manifest → manifest}/validation.d.ts +73 -31
- package/dist/manifest/validation.js +141 -0
- package/dist/manifest/validation.js.map +1 -0
- package/dist/{esm/mock.js → mock.js} +40 -42
- package/dist/mock.js.map +1 -0
- package/dist/namespace.d.ts +275 -0
- package/dist/namespace.js +225 -0
- package/dist/namespace.js.map +1 -0
- package/dist/notification.d.ts +66 -0
- package/dist/notification.js +58 -0
- package/dist/notification.js.map +1 -0
- package/dist/{types/npm.d.ts → npm.d.ts} +2 -0
- package/dist/npm.js +74 -0
- package/dist/npm.js.map +1 -0
- package/dist/path.js +21 -0
- package/dist/path.js.map +1 -0
- package/dist/{esm/post-process.js → post-process.js} +99 -110
- package/dist/post-process.js.map +1 -0
- package/dist/{types/snaps.d.ts → snaps.d.ts} +2 -9
- package/dist/snaps.js +202 -0
- package/dist/snaps.js.map +1 -0
- package/dist/{types/types.d.ts → types.d.ts} +5 -2
- package/dist/types.js +103 -0
- package/dist/types.js.map +1 -0
- package/dist/{esm/versions.js → versions.js} +18 -15
- package/dist/versions.js.map +1 -0
- package/dist/{esm/virtual-file → virtual-file}/VirtualFile.js +33 -47
- package/dist/virtual-file/VirtualFile.js.map +1 -0
- package/dist/virtual-file/index.browser.js +18 -0
- package/dist/virtual-file/index.browser.js.map +1 -0
- package/dist/virtual-file/index.js +19 -0
- package/dist/virtual-file/index.js.map +1 -0
- package/dist/virtual-file/toVirtualFile.js +30 -0
- package/dist/virtual-file/toVirtualFile.js.map +1 -0
- package/package.json +32 -61
- package/dist/cjs/array.js +0 -23
- package/dist/cjs/array.js.map +0 -1
- package/dist/cjs/caveats.js +0 -33
- package/dist/cjs/caveats.js.map +0 -1
- package/dist/cjs/checksum.js +0 -38
- package/dist/cjs/checksum.js.map +0 -1
- package/dist/cjs/cronjob.js +0 -84
- package/dist/cjs/cronjob.js.map +0 -1
- package/dist/cjs/deep-clone.js +0 -22
- package/dist/cjs/deep-clone.js.map +0 -1
- package/dist/cjs/default-endowments.js +0 -49
- package/dist/cjs/default-endowments.js.map +0 -1
- package/dist/cjs/entropy.js +0 -23
- package/dist/cjs/entropy.js.map +0 -1
- package/dist/cjs/enum.js +0 -16
- package/dist/cjs/enum.js.map +0 -1
- package/dist/cjs/eval-worker.js.map +0 -1
- package/dist/cjs/eval.js +0 -29
- package/dist/cjs/eval.js.map +0 -1
- package/dist/cjs/fs.js +0 -126
- package/dist/cjs/fs.js.map +0 -1
- package/dist/cjs/handlers.js +0 -6
- package/dist/cjs/handlers.js.map +0 -1
- package/dist/cjs/icon.js +0 -37
- package/dist/cjs/icon.js.map +0 -1
- package/dist/cjs/iframe.js +0 -59
- package/dist/cjs/iframe.js.map +0 -1
- package/dist/cjs/index.browser.js +0 -40
- package/dist/cjs/index.browser.js.map +0 -1
- package/dist/cjs/index.executionenv.js +0 -24
- package/dist/cjs/index.executionenv.js.map +0 -1
- package/dist/cjs/index.js +0 -45
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json-rpc.js +0 -46
- package/dist/cjs/json-rpc.js.map +0 -1
- package/dist/cjs/json.js +0 -16
- package/dist/cjs/json.js.map +0 -1
- package/dist/cjs/logging.js +0 -40
- package/dist/cjs/logging.js.map +0 -1
- package/dist/cjs/manifest/index.browser.js +0 -20
- package/dist/cjs/manifest/index.browser.js.map +0 -1
- package/dist/cjs/manifest/index.js +0 -21
- package/dist/cjs/manifest/index.js.map +0 -1
- package/dist/cjs/manifest/manifest.js +0 -239
- package/dist/cjs/manifest/manifest.js.map +0 -1
- package/dist/cjs/manifest/validation.js +0 -183
- package/dist/cjs/manifest/validation.js.map +0 -1
- package/dist/cjs/mock.js +0 -128
- package/dist/cjs/mock.js.map +0 -1
- package/dist/cjs/namespace.js +0 -124
- package/dist/cjs/namespace.js.map +0 -1
- package/dist/cjs/npm.js +0 -81
- package/dist/cjs/npm.js.map +0 -1
- package/dist/cjs/path.js +0 -21
- package/dist/cjs/path.js.map +0 -1
- package/dist/cjs/post-process.js +0 -328
- package/dist/cjs/post-process.js.map +0 -1
- package/dist/cjs/snaps.js +0 -230
- package/dist/cjs/snaps.js.map +0 -1
- package/dist/cjs/types.js +0 -117
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/validation.js +0 -22
- package/dist/cjs/validation.js.map +0 -1
- package/dist/cjs/versions.js +0 -47
- package/dist/cjs/versions.js.map +0 -1
- package/dist/cjs/virtual-file/VirtualFile.js +0 -85
- package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
- package/dist/cjs/virtual-file/index.browser.js +0 -20
- package/dist/cjs/virtual-file/index.browser.js.map +0 -1
- package/dist/cjs/virtual-file/index.js +0 -21
- package/dist/cjs/virtual-file/index.js.map +0 -1
- package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
- package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/esm/array.js.map +0 -1
- package/dist/esm/caveats.js +0 -23
- package/dist/esm/caveats.js.map +0 -1
- package/dist/esm/checksum.js +0 -36
- package/dist/esm/checksum.js.map +0 -1
- package/dist/esm/cronjob.js +0 -66
- package/dist/esm/cronjob.js.map +0 -1
- package/dist/esm/deep-clone.js +0 -7
- package/dist/esm/deep-clone.js.map +0 -1
- package/dist/esm/default-endowments.js.map +0 -1
- package/dist/esm/entropy.js +0 -6
- package/dist/esm/entropy.js.map +0 -1
- package/dist/esm/enum.js +0 -12
- package/dist/esm/enum.js.map +0 -1
- package/dist/esm/eval-worker.js +0 -47
- package/dist/esm/eval-worker.js.map +0 -1
- package/dist/esm/eval.js +0 -25
- package/dist/esm/eval.js.map +0 -1
- package/dist/esm/fs.js.map +0 -1
- package/dist/esm/handlers.js +0 -3
- package/dist/esm/handlers.js.map +0 -1
- package/dist/esm/icon.js +0 -11
- package/dist/esm/icon.js.map +0 -1
- package/dist/esm/iframe.js.map +0 -1
- package/dist/esm/index.browser.js +0 -23
- package/dist/esm/index.browser.js.map +0 -1
- package/dist/esm/index.executionenv.js +0 -7
- package/dist/esm/index.executionenv.js.map +0 -1
- package/dist/esm/index.js +0 -28
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json-rpc.js +0 -39
- package/dist/esm/json-rpc.js.map +0 -1
- package/dist/esm/json.js +0 -17
- package/dist/esm/json.js.map +0 -1
- package/dist/esm/logging.js.map +0 -1
- package/dist/esm/manifest/index.browser.js +0 -3
- package/dist/esm/manifest/index.browser.js.map +0 -1
- package/dist/esm/manifest/index.js +0 -4
- package/dist/esm/manifest/index.js.map +0 -1
- package/dist/esm/manifest/manifest.js.map +0 -1
- package/dist/esm/manifest/validation.js +0 -152
- package/dist/esm/manifest/validation.js.map +0 -1
- package/dist/esm/mock.js.map +0 -1
- package/dist/esm/namespace.js +0 -110
- package/dist/esm/namespace.js.map +0 -1
- package/dist/esm/npm.js +0 -70
- package/dist/esm/npm.js.map +0 -1
- package/dist/esm/path.js +0 -17
- package/dist/esm/path.js.map +0 -1
- package/dist/esm/post-process.js.map +0 -1
- package/dist/esm/snaps.js +0 -215
- package/dist/esm/snaps.js.map +0 -1
- package/dist/esm/types.js +0 -85
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/validation.js +0 -17
- package/dist/esm/validation.js.map +0 -1
- package/dist/esm/versions.js.map +0 -1
- package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
- package/dist/esm/virtual-file/index.browser.js +0 -3
- package/dist/esm/virtual-file/index.browser.js.map +0 -1
- package/dist/esm/virtual-file/index.js +0 -4
- package/dist/esm/virtual-file/index.js.map +0 -1
- package/dist/esm/virtual-file/toVirtualFile.js +0 -26
- package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/types/enum.d.ts +0 -30
- package/dist/types/icon.d.ts +0 -4
- package/dist/types/json.d.ts +0 -13
- package/dist/types/namespace.d.ts +0 -124
- package/dist/types/validation.d.ts +0 -8
- /package/dist/{types/array.d.ts → array.d.ts} +0 -0
- /package/dist/{types/checksum.d.ts → checksum.d.ts} +0 -0
- /package/dist/{types/cronjob.d.ts → cronjob.d.ts} +0 -0
- /package/dist/{types/deep-clone.d.ts → deep-clone.d.ts} +0 -0
- /package/dist/{types/default-endowments.d.ts → default-endowments.d.ts} +0 -0
- /package/dist/{types/entropy.d.ts → entropy.d.ts} +0 -0
- /package/dist/{types/eval-worker.d.ts → eval-worker.d.ts} +0 -0
- /package/dist/{types/eval.d.ts → eval.d.ts} +0 -0
- /package/dist/{types/fs.d.ts → fs.d.ts} +0 -0
- /package/dist/{types/iframe.test.browser.d.ts → iframe.test.browser.d.ts} +0 -0
- /package/dist/{types/index.executionenv.d.ts → index.executionenv.d.ts} +0 -0
- /package/dist/{types/json-rpc.d.ts → json-rpc.d.ts} +0 -0
- /package/dist/{types/logging.d.ts → logging.d.ts} +0 -0
- /package/dist/{types/manifest → manifest}/index.browser.d.ts +0 -0
- /package/dist/{types/manifest → manifest}/index.d.ts +0 -0
- /package/dist/{types/manifest → manifest}/manifest.d.ts +0 -0
- /package/dist/{types/mock.d.ts → mock.d.ts} +0 -0
- /package/dist/{types/path.d.ts → path.d.ts} +0 -0
- /package/dist/{types/post-process.d.ts → post-process.d.ts} +0 -0
- /package/dist/{types/versions.d.ts → versions.d.ts} +0 -0
- /package/dist/{types/virtual-file → virtual-file}/VirtualFile.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/index.browser.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/index.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/toVirtualFile.d.ts +0 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertIsNamespacesObject = exports.isNamespacesObject = exports.isNamespace = exports.assertIsMultiChainRequest = exports.isMultiChainRequest = exports.assertIsConnectArguments = exports.isConnectArguments = exports.isAccountIdArray = exports.isAccountId = exports.isChainId = exports.isNamespaceId = exports.MultiChainRequestStruct = exports.RequestArgumentsStruct = exports.ConnectArgumentsStruct = exports.assertIsSession = exports.SessionStruct = exports.NamespacesStruct = exports.NamespaceIdStruct = exports.SessionNamespaceStruct = exports.RequestNamespaceStruct = exports.NamespaceStruct = exports.ChainStruct = exports.AccountIdArrayStruct = exports.AccountIdStruct = exports.ChainIdStruct = exports.LimitedString = exports.parseAccountId = exports.parseChainId = exports.ACCOUNT_ID_REGEX = exports.CHAIN_ID_REGEX = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const superstruct_1 = require("superstruct");
|
|
6
|
+
exports.CHAIN_ID_REGEX = /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u;
|
|
7
|
+
exports.ACCOUNT_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})):(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;
|
|
8
|
+
/**
|
|
9
|
+
* Parse a chain ID string to an object containing the namespace and reference.
|
|
10
|
+
* This validates the chain ID before parsing it.
|
|
11
|
+
*
|
|
12
|
+
* @param chainId - The chain ID to validate and parse.
|
|
13
|
+
* @returns The parsed chain ID.
|
|
14
|
+
*/
|
|
15
|
+
function parseChainId(chainId) {
|
|
16
|
+
const match = exports.CHAIN_ID_REGEX.exec(chainId);
|
|
17
|
+
if (!match?.groups) {
|
|
18
|
+
throw new Error('Invalid chain ID.');
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
namespace: match.groups.namespace,
|
|
22
|
+
reference: match.groups.reference,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.parseChainId = parseChainId;
|
|
26
|
+
/**
|
|
27
|
+
* Parse an account ID to an object containing the chain, chain ID and address.
|
|
28
|
+
* This validates the account ID before parsing it.
|
|
29
|
+
*
|
|
30
|
+
* @param accountId - The account ID to validate and parse.
|
|
31
|
+
* @returns The parsed account ID.
|
|
32
|
+
*/
|
|
33
|
+
function parseAccountId(accountId) {
|
|
34
|
+
const match = exports.ACCOUNT_ID_REGEX.exec(accountId);
|
|
35
|
+
if (!match?.groups) {
|
|
36
|
+
throw new Error('Invalid account ID.');
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
address: match.groups.accountAddress,
|
|
40
|
+
chainId: match.groups.chainId,
|
|
41
|
+
chain: {
|
|
42
|
+
namespace: match.groups.namespace,
|
|
43
|
+
reference: match.groups.reference,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.parseAccountId = parseAccountId;
|
|
48
|
+
/**
|
|
49
|
+
* A helper struct for a string with a minimum length of 1 and a maximum length
|
|
50
|
+
* of 40.
|
|
51
|
+
*/
|
|
52
|
+
exports.LimitedString = (0, superstruct_1.size)((0, superstruct_1.string)(), 1, 40);
|
|
53
|
+
/**
|
|
54
|
+
* A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
|
|
55
|
+
*/
|
|
56
|
+
exports.ChainIdStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), exports.CHAIN_ID_REGEX);
|
|
57
|
+
exports.AccountIdStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), exports.ACCOUNT_ID_REGEX);
|
|
58
|
+
exports.AccountIdArrayStruct = (0, superstruct_1.array)(exports.AccountIdStruct);
|
|
59
|
+
/**
|
|
60
|
+
* A chain descriptor.
|
|
61
|
+
*/
|
|
62
|
+
exports.ChainStruct = (0, superstruct_1.object)({
|
|
63
|
+
id: exports.ChainIdStruct,
|
|
64
|
+
name: exports.LimitedString,
|
|
65
|
+
});
|
|
66
|
+
exports.NamespaceStruct = (0, superstruct_1.object)({
|
|
67
|
+
/**
|
|
68
|
+
* A list of supported chains in the namespace.
|
|
69
|
+
*/
|
|
70
|
+
chains: (0, superstruct_1.array)(exports.ChainStruct),
|
|
71
|
+
/**
|
|
72
|
+
* A list of supported RPC methods on the namespace, that a DApp can call.
|
|
73
|
+
*/
|
|
74
|
+
methods: (0, superstruct_1.optional)((0, superstruct_1.array)(exports.LimitedString)),
|
|
75
|
+
/**
|
|
76
|
+
* A list of supported RPC events on the namespace, that a DApp can listen to.
|
|
77
|
+
*/
|
|
78
|
+
events: (0, superstruct_1.optional)((0, superstruct_1.array)(exports.LimitedString)),
|
|
79
|
+
});
|
|
80
|
+
exports.RequestNamespaceStruct = (0, superstruct_1.assign)((0, superstruct_1.omit)(exports.NamespaceStruct, ['chains']), (0, superstruct_1.object)({ chains: (0, superstruct_1.array)(exports.ChainIdStruct) }));
|
|
81
|
+
exports.SessionNamespaceStruct = (0, superstruct_1.assign)(exports.RequestNamespaceStruct, (0, superstruct_1.object)({ accounts: (0, superstruct_1.array)(exports.AccountIdStruct) }));
|
|
82
|
+
/**
|
|
83
|
+
* A CAIP-2 namespace, i.e., the first part of a chain ID.
|
|
84
|
+
*/
|
|
85
|
+
exports.NamespaceIdStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^[-a-z0-9]{3,8}$/u);
|
|
86
|
+
/**
|
|
87
|
+
* An object mapping CAIP-2 namespaces to their values.
|
|
88
|
+
*/
|
|
89
|
+
exports.NamespacesStruct = (0, superstruct_1.record)(exports.NamespaceIdStruct, exports.NamespaceStruct);
|
|
90
|
+
exports.SessionStruct = (0, superstruct_1.object)({
|
|
91
|
+
namespaces: (0, superstruct_1.record)(exports.NamespaceIdStruct, exports.SessionNamespaceStruct),
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Asserts that the given value is a valid {@link Session}.
|
|
95
|
+
*
|
|
96
|
+
* @param value - The value to assert.
|
|
97
|
+
* @throws If the value is not a valid {@link Session}.
|
|
98
|
+
*/
|
|
99
|
+
function assertIsSession(value) {
|
|
100
|
+
(0, utils_1.assertStruct)(value, exports.SessionStruct, 'Invalid session');
|
|
101
|
+
}
|
|
102
|
+
exports.assertIsSession = assertIsSession;
|
|
103
|
+
exports.ConnectArgumentsStruct = (0, superstruct_1.object)({
|
|
104
|
+
requiredNamespaces: (0, superstruct_1.record)(exports.NamespaceIdStruct, exports.RequestNamespaceStruct),
|
|
105
|
+
});
|
|
106
|
+
exports.RequestArgumentsStruct = (0, superstruct_1.assign)((0, superstruct_1.partial)((0, superstruct_1.pick)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc'])), (0, superstruct_1.omit)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc']));
|
|
107
|
+
exports.MultiChainRequestStruct = (0, superstruct_1.object)({
|
|
108
|
+
chainId: exports.ChainIdStruct,
|
|
109
|
+
request: exports.RequestArgumentsStruct,
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* Check if the given value is a CAIP-2 namespace ID.
|
|
113
|
+
*
|
|
114
|
+
* @param value - The value to check.
|
|
115
|
+
* @returns Whether the value is a CAIP-2 namespace ID.
|
|
116
|
+
*/
|
|
117
|
+
function isNamespaceId(value) {
|
|
118
|
+
return (0, superstruct_1.is)(value, exports.NamespaceIdStruct);
|
|
119
|
+
}
|
|
120
|
+
exports.isNamespaceId = isNamespaceId;
|
|
121
|
+
/**
|
|
122
|
+
* Check if the given value is a CAIP-2 chain ID.
|
|
123
|
+
*
|
|
124
|
+
* @param value - The value to check.
|
|
125
|
+
* @returns Whether the value is a CAIP-2 chain ID.
|
|
126
|
+
*/
|
|
127
|
+
function isChainId(value) {
|
|
128
|
+
return (0, superstruct_1.is)(value, exports.ChainIdStruct);
|
|
129
|
+
}
|
|
130
|
+
exports.isChainId = isChainId;
|
|
131
|
+
/**
|
|
132
|
+
* Check if the given value is a CAIP-10 account ID.
|
|
133
|
+
*
|
|
134
|
+
* @param value - The value to check.
|
|
135
|
+
* @returns Whether the value is a CAIP-10 account ID.
|
|
136
|
+
*/
|
|
137
|
+
function isAccountId(value) {
|
|
138
|
+
return (0, superstruct_1.is)(value, exports.AccountIdStruct);
|
|
139
|
+
}
|
|
140
|
+
exports.isAccountId = isAccountId;
|
|
141
|
+
/**
|
|
142
|
+
* Check if the given value is an array of CAIP-10 account IDs.
|
|
143
|
+
*
|
|
144
|
+
* @param value - The value to check.
|
|
145
|
+
* @returns Whether the value is an array of CAIP-10 account IDs.
|
|
146
|
+
*/
|
|
147
|
+
function isAccountIdArray(value) {
|
|
148
|
+
return (0, superstruct_1.is)(value, exports.AccountIdArrayStruct);
|
|
149
|
+
}
|
|
150
|
+
exports.isAccountIdArray = isAccountIdArray;
|
|
151
|
+
/**
|
|
152
|
+
* Check if the given value is a {@link ConnectArguments} object.
|
|
153
|
+
*
|
|
154
|
+
* @param value - The value to check.
|
|
155
|
+
* @returns Whether the value is a valid {@link ConnectArguments} object.
|
|
156
|
+
*/
|
|
157
|
+
function isConnectArguments(value) {
|
|
158
|
+
return (0, superstruct_1.is)(value, exports.ConnectArgumentsStruct);
|
|
159
|
+
}
|
|
160
|
+
exports.isConnectArguments = isConnectArguments;
|
|
161
|
+
/**
|
|
162
|
+
* Assert that the given value is a {@link ConnectArguments} object.
|
|
163
|
+
*
|
|
164
|
+
* @param value - The value to check.
|
|
165
|
+
* @throws If the value is not a valid {@link ConnectArguments} object.
|
|
166
|
+
*/
|
|
167
|
+
function assertIsConnectArguments(value) {
|
|
168
|
+
(0, utils_1.assertStruct)(value, exports.ConnectArgumentsStruct, 'Invalid connect arguments');
|
|
169
|
+
}
|
|
170
|
+
exports.assertIsConnectArguments = assertIsConnectArguments;
|
|
171
|
+
/**
|
|
172
|
+
* Check if the given value is a {@link MultiChainRequest} object.
|
|
173
|
+
*
|
|
174
|
+
* @param value - The value to check.
|
|
175
|
+
* @returns Whether the value is a valid {@link MultiChainRequest} object.
|
|
176
|
+
*/
|
|
177
|
+
function isMultiChainRequest(value) {
|
|
178
|
+
return (0, superstruct_1.is)(value, exports.MultiChainRequestStruct);
|
|
179
|
+
}
|
|
180
|
+
exports.isMultiChainRequest = isMultiChainRequest;
|
|
181
|
+
/**
|
|
182
|
+
* Assert that the given value is a {@link MultiChainRequest} object.
|
|
183
|
+
*
|
|
184
|
+
* @param value - The value to check.
|
|
185
|
+
* @throws If the value is not a valid {@link MultiChainRequest} object.
|
|
186
|
+
*/
|
|
187
|
+
function assertIsMultiChainRequest(value) {
|
|
188
|
+
(0, utils_1.assertStruct)(value, exports.MultiChainRequestStruct, 'Invalid request arguments');
|
|
189
|
+
}
|
|
190
|
+
exports.assertIsMultiChainRequest = assertIsMultiChainRequest;
|
|
191
|
+
/**
|
|
192
|
+
* Check if a value is a {@link Namespace}.
|
|
193
|
+
*
|
|
194
|
+
* @param value - The value to validate.
|
|
195
|
+
* @returns True if the value is a valid {@link Namespace}.
|
|
196
|
+
*/
|
|
197
|
+
function isNamespace(value) {
|
|
198
|
+
return (0, superstruct_1.is)(value, exports.NamespaceStruct);
|
|
199
|
+
}
|
|
200
|
+
exports.isNamespace = isNamespace;
|
|
201
|
+
/**
|
|
202
|
+
* Check if a value is an object containing {@link Namespace}s.
|
|
203
|
+
*
|
|
204
|
+
* @param value - The value to validate.
|
|
205
|
+
* @returns True if the value is a valid object containing namespaces.
|
|
206
|
+
*/
|
|
207
|
+
function isNamespacesObject(value) {
|
|
208
|
+
return (0, superstruct_1.is)(value, exports.NamespacesStruct);
|
|
209
|
+
}
|
|
210
|
+
exports.isNamespacesObject = isNamespacesObject;
|
|
211
|
+
/**
|
|
212
|
+
* Assert that the given value is a {@link Namespaces} object.
|
|
213
|
+
*
|
|
214
|
+
* @param value - The value to check.
|
|
215
|
+
* @param ErrorWrapper - The error wrapper to use. Defaults to
|
|
216
|
+
* {@link AssertionError}.
|
|
217
|
+
* @throws If the value is not a valid {@link Namespaces} object.
|
|
218
|
+
*/
|
|
219
|
+
function assertIsNamespacesObject(value,
|
|
220
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
221
|
+
ErrorWrapper) {
|
|
222
|
+
(0, utils_1.assertStruct)(value, exports.NamespacesStruct, 'Invalid namespaces object', ErrorWrapper);
|
|
223
|
+
}
|
|
224
|
+
exports.assertIsNamespacesObject = assertIsNamespacesObject;
|
|
225
|
+
//# sourceMappingURL=namespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../src/namespace.ts"],"names":[],"mappings":";;;AAAA,2CAIyB;AACzB,6CAcqB;AAER,QAAA,cAAc,GACzB,kEAAkE,CAAC;AAExD,QAAA,gBAAgB,GAC3B,mHAAmH,CAAC;AAEtH;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,OAAgB;IAI3C,MAAM,KAAK,GAAG,sBAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;KACtC;IAED,OAAO;QACL,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS;QACjC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS;KAClC,CAAC;AACJ,CAAC;AAbD,oCAaC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,SAAoB;IAKjD,MAAM,KAAK,GAAG,wBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;KACxC;IAED,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,cAAc;QACpC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,OAAkB;QACxC,KAAK,EAAE;YACL,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS;YACjC,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS;SAClC;KACF,CAAC;AACJ,CAAC;AAlBD,wCAkBC;AAED;;;GAGG;AACU,QA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ertionErrorConstructor,\n assertStruct,\n} from '@metamask/utils';\nimport {\n array,\n Infer,\n is,\n object,\n optional,\n pattern,\n record,\n size,\n string,\n omit,\n assign,\n partial,\n pick,\n} from 'superstruct';\n\nexport const CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u;\n\nexport const ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})):(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;\n\n/**\n * Parse a chain ID string to an object containing the namespace and reference.\n * This validates the chain ID before parsing it.\n *\n * @param chainId - The chain ID to validate and parse.\n * @returns The parsed chain ID.\n */\nexport function parseChainId(chainId: ChainId): {\n namespace: NamespaceId;\n reference: string;\n} {\n const match = CHAIN_ID_REGEX.exec(chainId);\n if (!match?.groups) {\n throw new Error('Invalid chain ID.');\n }\n\n return {\n namespace: match.groups.namespace,\n reference: match.groups.reference,\n };\n}\n\n/**\n * Parse an account ID to an object containing the chain, chain ID and address.\n * This validates the account ID before parsing it.\n *\n * @param accountId - The account ID to validate and parse.\n * @returns The parsed account ID.\n */\nexport function parseAccountId(accountId: AccountId): {\n chain: { namespace: NamespaceId; reference: string };\n chainId: ChainId;\n address: string;\n} {\n const match = ACCOUNT_ID_REGEX.exec(accountId);\n if (!match?.groups) {\n throw new Error('Invalid account ID.');\n }\n\n return {\n address: match.groups.accountAddress,\n chainId: match.groups.chainId as ChainId,\n chain: {\n namespace: match.groups.namespace,\n reference: match.groups.reference,\n },\n };\n}\n\n/**\n * A helper struct for a string with a minimum length of 1 and a maximum length\n * of 40.\n */\nexport const LimitedString = size(string(), 1, 40);\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const ChainIdStruct = pattern(string(), CHAIN_ID_REGEX);\nexport type ChainId = `${string}:${string}`;\n\nexport const AccountIdStruct = pattern(string(), ACCOUNT_ID_REGEX);\nexport type AccountId = `${ChainId}:${string}`;\n\nexport const AccountIdArrayStruct = array(AccountIdStruct);\n\n/**\n * A chain descriptor.\n */\nexport const ChainStruct = object({\n id: ChainIdStruct,\n name: LimitedString,\n});\nexport type Chain = Infer<typeof ChainStruct>;\n\nexport const NamespaceStruct = object({\n /**\n * A list of supported chains in the namespace.\n */\n chains: array(ChainStruct),\n\n /**\n * A list of supported RPC methods on the namespace, that a DApp can call.\n */\n methods: optional(array(LimitedString)),\n\n /**\n * A list of supported RPC events on the namespace, that a DApp can listen to.\n */\n events: optional(array(LimitedString)),\n});\nexport type Namespace = Infer<typeof NamespaceStruct>;\n\nexport const RequestNamespaceStruct = assign(\n omit(NamespaceStruct, ['chains']),\n object({ chains: array(ChainIdStruct) }),\n);\nexport type RequestNamespace = Infer<typeof RequestNamespaceStruct>;\n\nexport const SessionNamespaceStruct = assign(\n RequestNamespaceStruct,\n object({ accounts: array(AccountIdStruct) }),\n);\nexport type SessionNamespace = Infer<typeof SessionNamespaceStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a chain ID.\n */\nexport const NamespaceIdStruct = pattern(string(), /^[-a-z0-9]{3,8}$/u);\nexport type NamespaceId = Infer<typeof NamespaceIdStruct>;\n\n/**\n * An object mapping CAIP-2 namespaces to their values.\n */\nexport const NamespacesStruct = record(NamespaceIdStruct, NamespaceStruct);\nexport type Namespaces = Infer<typeof NamespacesStruct>;\n\nexport const SessionStruct = object({\n namespaces: record(NamespaceIdStruct, SessionNamespaceStruct),\n});\nexport type Session = Infer<typeof SessionStruct>;\n\n/**\n * Asserts that the given value is a valid {@link Session}.\n *\n * @param value - The value to assert.\n * @throws If the value is not a valid {@link Session}.\n */\nexport function assertIsSession(value: unknown): asserts value is Session {\n assertStruct(value, SessionStruct, 'Invalid session');\n}\n\nexport const ConnectArgumentsStruct = object({\n requiredNamespaces: record(NamespaceIdStruct, RequestNamespaceStruct),\n});\nexport type ConnectArguments = Infer<typeof ConnectArgumentsStruct>;\n\nexport const RequestArgumentsStruct = assign(\n partial(pick(JsonRpcRequestStruct, ['id', 'jsonrpc'])),\n omit(JsonRpcRequestStruct, ['id', 'jsonrpc']),\n);\nexport type RequestArguments = Infer<typeof RequestArgumentsStruct>;\n\nexport const MultiChainRequestStruct = object({\n chainId: ChainIdStruct,\n request: RequestArgumentsStruct,\n});\nexport type MultiChainRequest = Infer<typeof MultiChainRequestStruct>;\n\n/**\n * Check if the given value is a CAIP-2 namespace ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-2 namespace ID.\n */\nexport function isNamespaceId(value: unknown): value is NamespaceId {\n return is(value, NamespaceIdStruct);\n}\n\n/**\n * Check if the given value is a CAIP-2 chain ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-2 chain ID.\n */\nexport function isChainId(value: unknown): value is ChainId {\n return is(value, ChainIdStruct);\n}\n\n/**\n * Check if the given value is a CAIP-10 account ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-10 account ID.\n */\nexport function isAccountId(value: unknown): value is AccountId {\n return is(value, AccountIdStruct);\n}\n\n/**\n * Check if the given value is an array of CAIP-10 account IDs.\n *\n * @param value - The value to check.\n * @returns Whether the value is an array of CAIP-10 account IDs.\n */\nexport function isAccountIdArray(value: unknown): value is AccountId[] {\n return is(value, AccountIdArrayStruct);\n}\n\n/**\n * Check if the given value is a {@link ConnectArguments} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link ConnectArguments} object.\n */\nexport function isConnectArguments(value: unknown): value is ConnectArguments {\n return is(value, ConnectArgumentsStruct);\n}\n\n/**\n * Assert that the given value is a {@link ConnectArguments} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link ConnectArguments} object.\n */\nexport function assertIsConnectArguments(\n value: unknown,\n): asserts value is ConnectArguments {\n assertStruct(value, ConnectArgumentsStruct, 'Invalid connect arguments');\n}\n\n/**\n * Check if the given value is a {@link MultiChainRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link MultiChainRequest} object.\n */\nexport function isMultiChainRequest(\n value: unknown,\n): value is MultiChainRequest {\n return is(value, MultiChainRequestStruct);\n}\n\n/**\n * Assert that the given value is a {@link MultiChainRequest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link MultiChainRequest} object.\n */\nexport function assertIsMultiChainRequest(\n value: unknown,\n): asserts value is MultiChainRequest {\n assertStruct(value, MultiChainRequestStruct, 'Invalid request arguments');\n}\n\n/**\n * Check if a value is a {@link Namespace}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link Namespace}.\n */\nexport function isNamespace(value: unknown): value is Namespace {\n return is(value, NamespaceStruct);\n}\n\n/**\n * Check if a value is an object containing {@link Namespace}s.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid object containing namespaces.\n */\nexport function isNamespacesObject(value: unknown): value is Namespaces {\n return is(value, NamespacesStruct);\n}\n\n/**\n * Assert that the given value is a {@link Namespaces} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link Namespaces} object.\n */\nexport function assertIsNamespacesObject(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is Namespaces {\n assertStruct(\n value,\n NamespacesStruct,\n 'Invalid namespaces object',\n ErrorWrapper,\n );\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Infer } from 'superstruct';
|
|
2
|
+
export declare const EventStruct: import("superstruct").Struct<{
|
|
3
|
+
name: string;
|
|
4
|
+
data: unknown;
|
|
5
|
+
}, {
|
|
6
|
+
name: import("superstruct").Struct<string, null>;
|
|
7
|
+
data: import("superstruct").Struct<unknown, null>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare type Event = Infer<typeof EventStruct>;
|
|
10
|
+
/**
|
|
11
|
+
* Check if a value is a SIP-2 event.
|
|
12
|
+
*
|
|
13
|
+
* @param value - The value to check.
|
|
14
|
+
* @returns Whether the value is a SIP-2 event.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isEvent(value: unknown): value is Event;
|
|
17
|
+
/**
|
|
18
|
+
* Assert that a value is a SIP-2 event.
|
|
19
|
+
*
|
|
20
|
+
* @param value - The value to check.
|
|
21
|
+
* @throws If the value is not a SIP-2 event.
|
|
22
|
+
*/
|
|
23
|
+
export declare function assertIsEvent(value: unknown): asserts value is Event;
|
|
24
|
+
export declare const MetaMaskNotificationStruct: import("superstruct").Struct<{
|
|
25
|
+
params: {
|
|
26
|
+
chainId: string;
|
|
27
|
+
event: {
|
|
28
|
+
name: string;
|
|
29
|
+
data: unknown;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
method: "multichainHack_metamask_event";
|
|
33
|
+
}, {
|
|
34
|
+
method: import("superstruct").Struct<"multichainHack_metamask_event", "multichainHack_metamask_event">;
|
|
35
|
+
params: import("superstruct").Struct<{
|
|
36
|
+
chainId: string;
|
|
37
|
+
event: {
|
|
38
|
+
name: string;
|
|
39
|
+
data: unknown;
|
|
40
|
+
};
|
|
41
|
+
}, {
|
|
42
|
+
chainId: import("superstruct").Struct<string, null>;
|
|
43
|
+
event: import("superstruct").Struct<{
|
|
44
|
+
name: string;
|
|
45
|
+
data: unknown;
|
|
46
|
+
}, {
|
|
47
|
+
name: import("superstruct").Struct<string, null>;
|
|
48
|
+
data: import("superstruct").Struct<unknown, null>;
|
|
49
|
+
}>;
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
export declare type MetaMaskNotification = Infer<typeof MetaMaskNotificationStruct>;
|
|
53
|
+
/**
|
|
54
|
+
* Check if a value is a SIP-2 notification.
|
|
55
|
+
*
|
|
56
|
+
* @param value - The value to check.
|
|
57
|
+
* @returns Whether the value is a SIP-2 notification.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isMetaMaskNotification(value: unknown): value is MetaMaskNotification;
|
|
60
|
+
/**
|
|
61
|
+
* Assert that a value is a SIP-2 notification.
|
|
62
|
+
*
|
|
63
|
+
* @param value - The value to check.
|
|
64
|
+
* @throws If the value is not a SIP-2 notification.
|
|
65
|
+
*/
|
|
66
|
+
export declare function assertIsMetaMaskNotification(value: unknown): asserts value is MetaMaskNotification;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertIsMetaMaskNotification = exports.isMetaMaskNotification = exports.MetaMaskNotificationStruct = exports.assertIsEvent = exports.isEvent = exports.EventStruct = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const superstruct_1 = require("superstruct");
|
|
6
|
+
const namespace_1 = require("./namespace");
|
|
7
|
+
exports.EventStruct = (0, superstruct_1.object)({
|
|
8
|
+
name: (0, superstruct_1.string)(),
|
|
9
|
+
data: (0, superstruct_1.unknown)(),
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Check if a value is a SIP-2 event.
|
|
13
|
+
*
|
|
14
|
+
* @param value - The value to check.
|
|
15
|
+
* @returns Whether the value is a SIP-2 event.
|
|
16
|
+
*/
|
|
17
|
+
function isEvent(value) {
|
|
18
|
+
return (0, superstruct_1.is)(value, exports.EventStruct);
|
|
19
|
+
}
|
|
20
|
+
exports.isEvent = isEvent;
|
|
21
|
+
/**
|
|
22
|
+
* Assert that a value is a SIP-2 event.
|
|
23
|
+
*
|
|
24
|
+
* @param value - The value to check.
|
|
25
|
+
* @throws If the value is not a SIP-2 event.
|
|
26
|
+
*/
|
|
27
|
+
function assertIsEvent(value) {
|
|
28
|
+
(0, utils_1.assertStruct)(value, exports.EventStruct, 'Invalid event');
|
|
29
|
+
}
|
|
30
|
+
exports.assertIsEvent = assertIsEvent;
|
|
31
|
+
exports.MetaMaskNotificationStruct = (0, superstruct_1.object)({
|
|
32
|
+
method: (0, superstruct_1.literal)('multichainHack_metamask_event'),
|
|
33
|
+
params: (0, superstruct_1.object)({
|
|
34
|
+
chainId: namespace_1.ChainIdStruct,
|
|
35
|
+
event: exports.EventStruct,
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Check if a value is a SIP-2 notification.
|
|
40
|
+
*
|
|
41
|
+
* @param value - The value to check.
|
|
42
|
+
* @returns Whether the value is a SIP-2 notification.
|
|
43
|
+
*/
|
|
44
|
+
function isMetaMaskNotification(value) {
|
|
45
|
+
return (0, superstruct_1.is)(value, exports.MetaMaskNotificationStruct);
|
|
46
|
+
}
|
|
47
|
+
exports.isMetaMaskNotification = isMetaMaskNotification;
|
|
48
|
+
/**
|
|
49
|
+
* Assert that a value is a SIP-2 notification.
|
|
50
|
+
*
|
|
51
|
+
* @param value - The value to check.
|
|
52
|
+
* @throws If the value is not a SIP-2 notification.
|
|
53
|
+
*/
|
|
54
|
+
function assertIsMetaMaskNotification(value) {
|
|
55
|
+
(0, utils_1.assertStruct)(value, exports.MetaMaskNotificationStruct, 'Invalid notification');
|
|
56
|
+
}
|
|
57
|
+
exports.assertIsMetaMaskNotification = assertIsMetaMaskNotification;
|
|
58
|
+
//# sourceMappingURL=notification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../src/notification.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAC/C,6CAA0E;AAE1E,2CAA4C;AAE/B,QAAA,WAAW,GAAG,IAAA,oBAAM,EAAC;IAChC,IAAI,EAAE,IAAA,oBAAM,GAAE;IACd,IAAI,EAAE,IAAA,qBAAO,GAAE;CAChB,CAAC,CAAC;AAIH;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,KAAc;IACpC,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,mBAAW,CAAC,CAAC;AAChC,CAAC;AAFD,0BAEC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAA,oBAAY,EAAC,KAAK,EAAE,mBAAW,EAAE,eAAe,CAAC,CAAC;AACpD,CAAC;AAFD,sCAEC;AAEY,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,MAAM,EAAE,IAAA,qBAAO,EAAC,+BAA+B,CAAC;IAChD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,OAAO,EAAE,yBAAa;QACtB,KAAK,EAAE,mBAAW;KACnB,CAAC;CACH,CAAC,CAAC;AAIH;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,KAAc;IAEd,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,kCAA0B,CAAC,CAAC;AAC/C,CAAC;AAJD,wDAIC;AAED;;;;;GAKG;AACH,SAAgB,4BAA4B,CAC1C,KAAc;IAEd,IAAA,oBAAY,EAAC,KAAK,EAAE,kCAA0B,EAAE,sBAAsB,CAAC,CAAC;AAC1E,CAAC;AAJD,oEAIC","sourcesContent":["import { assertStruct } from '@metamask/utils';\nimport { Infer, is, literal, object, string, unknown } from 'superstruct';\n\nimport { ChainIdStruct } from './namespace';\n\nexport const EventStruct = object({\n name: string(),\n data: unknown(),\n});\n\nexport type Event = Infer<typeof EventStruct>;\n\n/**\n * Check if a value is a SIP-2 event.\n *\n * @param value - The value to check.\n * @returns Whether the value is a SIP-2 event.\n */\nexport function isEvent(value: unknown): value is Event {\n return is(value, EventStruct);\n}\n\n/**\n * Assert that a value is a SIP-2 event.\n *\n * @param value - The value to check.\n * @throws If the value is not a SIP-2 event.\n */\nexport function assertIsEvent(value: unknown): asserts value is Event {\n assertStruct(value, EventStruct, 'Invalid event');\n}\n\nexport const MetaMaskNotificationStruct = object({\n method: literal('multichainHack_metamask_event'),\n params: object({\n chainId: ChainIdStruct,\n event: EventStruct,\n }),\n});\n\nexport type MetaMaskNotification = Infer<typeof MetaMaskNotificationStruct>;\n\n/**\n * Check if a value is a SIP-2 notification.\n *\n * @param value - The value to check.\n * @returns Whether the value is a SIP-2 notification.\n */\nexport function isMetaMaskNotification(\n value: unknown,\n): value is MetaMaskNotification {\n return is(value, MetaMaskNotificationStruct);\n}\n\n/**\n * Assert that a value is a SIP-2 notification.\n *\n * @param value - The value to check.\n * @throws If the value is not a SIP-2 notification.\n */\nexport function assertIsMetaMaskNotification(\n value: unknown,\n): asserts value is MetaMaskNotification {\n assertStruct(value, MetaMaskNotificationStruct, 'Invalid notification');\n}\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { NpmSnapFileNames, SnapFiles, UnvalidatedSnapFiles } from './types';
|
|
2
|
+
export declare const SVG_MAX_BYTE_SIZE = 100000;
|
|
3
|
+
export declare const SVG_MAX_BYTE_SIZE_TEXT: string;
|
|
2
4
|
export declare const EXPECTED_SNAP_FILES: readonly ["manifest", "packageJson", "sourceCode"];
|
|
3
5
|
export declare const SnapFileNameFromKey: {
|
|
4
6
|
readonly manifest: NpmSnapFileNames.Manifest;
|
package/dist/npm.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateNpmSnap = exports.SnapFileNameFromKey = exports.EXPECTED_SNAP_FILES = exports.SVG_MAX_BYTE_SIZE_TEXT = exports.SVG_MAX_BYTE_SIZE = void 0;
|
|
4
|
+
const manifest_1 = require("./manifest/manifest");
|
|
5
|
+
const validation_1 = require("./manifest/validation");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
exports.SVG_MAX_BYTE_SIZE = 100000;
|
|
8
|
+
exports.SVG_MAX_BYTE_SIZE_TEXT = `${Math.floor(exports.SVG_MAX_BYTE_SIZE / 1000)}kb`;
|
|
9
|
+
exports.EXPECTED_SNAP_FILES = [
|
|
10
|
+
'manifest',
|
|
11
|
+
'packageJson',
|
|
12
|
+
'sourceCode',
|
|
13
|
+
];
|
|
14
|
+
exports.SnapFileNameFromKey = {
|
|
15
|
+
manifest: types_1.NpmSnapFileNames.Manifest,
|
|
16
|
+
packageJson: types_1.NpmSnapFileNames.PackageJson,
|
|
17
|
+
sourceCode: 'source code bundle',
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Validates the files extracted from an npm Snap package tarball by ensuring
|
|
21
|
+
* that they're non-empty and that the Json files match their respective schemas
|
|
22
|
+
* and the Snaps publishing specification.
|
|
23
|
+
*
|
|
24
|
+
* @param snapFiles - The object containing the expected Snap file contents,
|
|
25
|
+
* if any.
|
|
26
|
+
* @param errorPrefix - The prefix of the error message.
|
|
27
|
+
* @returns A tuple of the Snap manifest object and the Snap source code.
|
|
28
|
+
*/
|
|
29
|
+
function validateNpmSnap(snapFiles, errorPrefix) {
|
|
30
|
+
exports.EXPECTED_SNAP_FILES.forEach((key) => {
|
|
31
|
+
if (!snapFiles[key]) {
|
|
32
|
+
throw new Error(`${errorPrefix ?? ''}Missing file "${exports.SnapFileNameFromKey[key]}".`);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
// Typecast: We are assured that the required files exist if we get here.
|
|
36
|
+
const { manifest, packageJson, sourceCode, svgIcon } = snapFiles;
|
|
37
|
+
try {
|
|
38
|
+
(0, validation_1.assertIsSnapManifest)(manifest.result);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new Error(`${errorPrefix ?? ''}${error.message}`);
|
|
42
|
+
}
|
|
43
|
+
const validatedManifest = manifest;
|
|
44
|
+
const { iconPath } = validatedManifest.result.source.location.npm;
|
|
45
|
+
if (iconPath && !svgIcon) {
|
|
46
|
+
throw new Error(`Missing file "${iconPath}".`);
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
(0, types_1.assertIsNpmSnapPackageJson)(packageJson.result);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new Error(`${errorPrefix ?? ''}${error.message}`);
|
|
53
|
+
}
|
|
54
|
+
const validatedPackageJson = packageJson;
|
|
55
|
+
(0, manifest_1.validateNpmSnapManifest)({
|
|
56
|
+
manifest: validatedManifest,
|
|
57
|
+
packageJson: validatedPackageJson,
|
|
58
|
+
sourceCode,
|
|
59
|
+
svgIcon,
|
|
60
|
+
});
|
|
61
|
+
if (svgIcon) {
|
|
62
|
+
if (Buffer.byteLength(svgIcon.value, 'utf8') > exports.SVG_MAX_BYTE_SIZE) {
|
|
63
|
+
throw new Error(`${errorPrefix ?? ''}The specified SVG icon exceeds the maximum size of ${exports.SVG_MAX_BYTE_SIZE_TEXT}.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
manifest: validatedManifest,
|
|
68
|
+
packageJson: validatedPackageJson,
|
|
69
|
+
sourceCode,
|
|
70
|
+
svgIcon,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
exports.validateNpmSnap = validateNpmSnap;
|
|
74
|
+
//# sourceMappingURL=npm.js.map
|
package/dist/npm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npm.js","sourceRoot":"","sources":["../src/npm.ts"],"names":[],"mappings":";;;AAAA,kDAA8D;AAC9D,sDAA6D;AAC7D,mCAKiB;AAEJ,QAAA,iBAAiB,GAAG,MAAO,CAAC;AAC5B,QAAA,sBAAsB,GAAG,GAAG,IAAI,CAAC,KAAK,CACjD,yBAAiB,GAAG,IAAI,CACzB,IAAI,CAAC;AAEO,QAAA,mBAAmB,GAAG;IACjC,UAAU;IACV,aAAa;IACb,YAAY;CACJ,CAAC;AAEE,QAAA,mBAAmB,GAAG;IACjC,QAAQ,EAAE,wBAAgB,CAAC,QAAQ;IACnC,WAAW,EAAE,wBAAgB,CAAC,WAAW;IACzC,UAAU,EAAE,oBAAoB;CACxB,CAAC;AAEX;;;;;;;;;GASG;AACH,SAAgB,eAAe,CAC7B,SAA+B,EAC/B,WAA2B;IAE3B,2BAAmB,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAClC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;YACnB,MAAM,IAAI,KAAK,CACb,GAAG,WAAW,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,QAAQ,EAAE,iBAAiB;QAC3B,WAAW,EAAE,oBAAoB;QACjC,UAAU;QACV,OAAO;KACR,CAAC;AACJ,CAAC;AAxDD,0CAwDC","sourcesContent":["import { validateNpmSnapManifest } from './manifest/manifest';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport {\n assertIsNpmSnapPackageJson,\n NpmSnapFileNames,\n SnapFiles,\n UnvalidatedSnapFiles,\n} from './types';\n\nexport const SVG_MAX_BYTE_SIZE = 100_000;\nexport const SVG_MAX_BYTE_SIZE_TEXT = `${Math.floor(\n SVG_MAX_BYTE_SIZE / 1000,\n)}kb`;\n\nexport const EXPECTED_SNAP_FILES = [\n 'manifest',\n 'packageJson',\n 'sourceCode',\n] as const;\n\nexport const SnapFileNameFromKey = {\n manifest: NpmSnapFileNames.Manifest,\n packageJson: NpmSnapFileNames.PackageJson,\n sourceCode: 'source code bundle',\n} as const;\n\n/**\n * Validates the files extracted from an npm Snap package tarball by ensuring\n * that they're non-empty and that the Json files match their respective schemas\n * and the Snaps publishing specification.\n *\n * @param snapFiles - The object containing the expected Snap file contents,\n * if any.\n * @param errorPrefix - The prefix of the error message.\n * @returns A tuple of the Snap manifest object and the Snap source code.\n */\nexport function validateNpmSnap(\n snapFiles: UnvalidatedSnapFiles,\n errorPrefix?: `${string}: `,\n): SnapFiles {\n EXPECTED_SNAP_FILES.forEach((key) => {\n if (!snapFiles[key]) {\n throw new Error(\n `${errorPrefix ?? ''}Missing file \"${SnapFileNameFromKey[key]}\".`,\n );\n }\n });\n\n // Typecast: We are assured that the required files exist if we get here.\n const { manifest, packageJson, sourceCode, svgIcon } = snapFiles as SnapFiles;\n try {\n assertIsSnapManifest(manifest.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n const validatedManifest = manifest;\n\n const { iconPath } = validatedManifest.result.source.location.npm;\n if (iconPath && !svgIcon) {\n throw new Error(`Missing file \"${iconPath}\".`);\n }\n\n try {\n assertIsNpmSnapPackageJson(packageJson.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n const validatedPackageJson = packageJson;\n\n validateNpmSnapManifest({\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n });\n\n if (svgIcon) {\n if (Buffer.byteLength(svgIcon.value, 'utf8') > SVG_MAX_BYTE_SIZE) {\n throw new Error(\n `${\n errorPrefix ?? ''\n }The specified SVG icon exceeds the maximum size of ${SVG_MAX_BYTE_SIZE_TEXT}.`,\n );\n }\n }\n\n return {\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n };\n}\n"]}
|
package/dist/path.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeRelative = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes relative paths by optionally removing `./` prefix.
|
|
7
|
+
*
|
|
8
|
+
* @param path - Path to make normalize.
|
|
9
|
+
* @returns The same path, with `./` prefix remove.
|
|
10
|
+
*/
|
|
11
|
+
// TODO(ritave): Include NodeJS path polyfill and use path.normalize as well
|
|
12
|
+
function normalizeRelative(path) {
|
|
13
|
+
(0, utils_1.assert)(!path.startsWith('/'));
|
|
14
|
+
(0, utils_1.assert)(path.search(/:|\/\//u) === -1, `Path "${path}" potentially an URI instead of local relative`);
|
|
15
|
+
if (path.startsWith('./')) {
|
|
16
|
+
return path.slice(2);
|
|
17
|
+
}
|
|
18
|
+
return path;
|
|
19
|
+
}
|
|
20
|
+
exports.normalizeRelative = normalizeRelative;
|
|
21
|
+
//# sourceMappingURL=path.js.map
|
package/dist/path.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AAEzC;;;;;GAKG;AACH,4EAA4E;AAC5E,SAAgB,iBAAiB,CAAC,IAAY;IAC5C,IAAA,cAAM,EAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9B,IAAA,cAAM,EACJ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAC7B,SAAS,IAAI,gDAAgD,CAC9D,CAAC;IAEF,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACtB;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,8CAWC","sourcesContent":["import { assert } from '@metamask/utils';\n\n/**\n * Normalizes relative paths by optionally removing `./` prefix.\n *\n * @param path - Path to make normalize.\n * @returns The same path, with `./` prefix remove.\n */\n// TODO(ritave): Include NodeJS path polyfill and use path.normalize as well\nexport function normalizeRelative(path: string): string {\n assert(!path.startsWith('/'));\n assert(\n path.search(/:|\\/\\//u) === -1,\n `Path \"${path}\" potentially an URI instead of local relative`,\n );\n\n if (path.startsWith('./')) {\n return path.slice(2);\n }\n return path;\n}\n"]}
|