@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
package/dist/cjs/snaps.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
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
|
-
SnapStatus: function() {
|
|
13
|
-
return SnapStatus;
|
|
14
|
-
},
|
|
15
|
-
SnapStatusEvents: function() {
|
|
16
|
-
return SnapStatusEvents;
|
|
17
|
-
},
|
|
18
|
-
PROPOSED_NAME_REGEX: function() {
|
|
19
|
-
return PROPOSED_NAME_REGEX;
|
|
20
|
-
},
|
|
21
|
-
ProgrammaticallyFixableSnapError: function() {
|
|
22
|
-
return ProgrammaticallyFixableSnapError;
|
|
23
|
-
},
|
|
24
|
-
getSnapChecksum: function() {
|
|
25
|
-
return getSnapChecksum;
|
|
26
|
-
},
|
|
27
|
-
validateSnapShasum: function() {
|
|
28
|
-
return validateSnapShasum;
|
|
29
|
-
},
|
|
30
|
-
LOCALHOST_HOSTNAMES: function() {
|
|
31
|
-
return LOCALHOST_HOSTNAMES;
|
|
32
|
-
},
|
|
33
|
-
BaseSnapIdStruct: function() {
|
|
34
|
-
return BaseSnapIdStruct;
|
|
35
|
-
},
|
|
36
|
-
LocalSnapIdStruct: function() {
|
|
37
|
-
return LocalSnapIdStruct;
|
|
38
|
-
},
|
|
39
|
-
NpmSnapIdStruct: function() {
|
|
40
|
-
return NpmSnapIdStruct;
|
|
41
|
-
},
|
|
42
|
-
HttpSnapIdStruct: function() {
|
|
43
|
-
return HttpSnapIdStruct;
|
|
44
|
-
},
|
|
45
|
-
SnapIdStruct: function() {
|
|
46
|
-
return SnapIdStruct;
|
|
47
|
-
},
|
|
48
|
-
getSnapPrefix: function() {
|
|
49
|
-
return getSnapPrefix;
|
|
50
|
-
},
|
|
51
|
-
stripSnapPrefix: function() {
|
|
52
|
-
return stripSnapPrefix;
|
|
53
|
-
},
|
|
54
|
-
assertIsValidSnapId: function() {
|
|
55
|
-
return assertIsValidSnapId;
|
|
56
|
-
},
|
|
57
|
-
isCaipChainId: function() {
|
|
58
|
-
return isCaipChainId;
|
|
59
|
-
},
|
|
60
|
-
isSnapPermitted: function() {
|
|
61
|
-
return isSnapPermitted;
|
|
62
|
-
},
|
|
63
|
-
verifyRequestedSnapPermissions: function() {
|
|
64
|
-
return verifyRequestedSnapPermissions;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
const _utils = require("@metamask/utils");
|
|
68
|
-
const _base = require("@scure/base");
|
|
69
|
-
const _fastjsonstablestringify = /*#__PURE__*/ _interop_require_default(require("fast-json-stable-stringify"));
|
|
70
|
-
const _superstruct = require("superstruct");
|
|
71
|
-
const _validatenpmpackagename = /*#__PURE__*/ _interop_require_default(require("validate-npm-package-name"));
|
|
72
|
-
const _caveats = require("./caveats");
|
|
73
|
-
const _checksum = require("./checksum");
|
|
74
|
-
const _types = require("./types");
|
|
75
|
-
function _define_property(obj, key, value) {
|
|
76
|
-
if (key in obj) {
|
|
77
|
-
Object.defineProperty(obj, key, {
|
|
78
|
-
value: value,
|
|
79
|
-
enumerable: true,
|
|
80
|
-
configurable: true,
|
|
81
|
-
writable: true
|
|
82
|
-
});
|
|
83
|
-
} else {
|
|
84
|
-
obj[key] = value;
|
|
85
|
-
}
|
|
86
|
-
return obj;
|
|
87
|
-
}
|
|
88
|
-
function _interop_require_default(obj) {
|
|
89
|
-
return obj && obj.__esModule ? obj : {
|
|
90
|
-
default: obj
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const PROPOSED_NAME_REGEX = /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u;
|
|
94
|
-
var SnapStatus;
|
|
95
|
-
(function(SnapStatus) {
|
|
96
|
-
SnapStatus["Installing"] = 'installing';
|
|
97
|
-
SnapStatus["Updating"] = 'updating';
|
|
98
|
-
SnapStatus["Running"] = 'running';
|
|
99
|
-
SnapStatus["Stopped"] = 'stopped';
|
|
100
|
-
SnapStatus["Crashed"] = 'crashed';
|
|
101
|
-
})(SnapStatus || (SnapStatus = {}));
|
|
102
|
-
var SnapStatusEvents;
|
|
103
|
-
(function(SnapStatusEvents) {
|
|
104
|
-
SnapStatusEvents["Start"] = 'START';
|
|
105
|
-
SnapStatusEvents["Stop"] = 'STOP';
|
|
106
|
-
SnapStatusEvents["Crash"] = 'CRASH';
|
|
107
|
-
SnapStatusEvents["Update"] = 'UPDATE';
|
|
108
|
-
})(SnapStatusEvents || (SnapStatusEvents = {}));
|
|
109
|
-
class ProgrammaticallyFixableSnapError extends Error {
|
|
110
|
-
constructor(message, reason){
|
|
111
|
-
super(message);
|
|
112
|
-
_define_property(this, "reason", void 0);
|
|
113
|
-
this.reason = reason;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Gets a checksummable manifest by removing the shasum property and reserializing the JSON using a deterministic algorithm.
|
|
118
|
-
*
|
|
119
|
-
* @param manifest - The manifest itself.
|
|
120
|
-
* @returns A virtual file containing the checksummable manifest.
|
|
121
|
-
*/ function getChecksummableManifest(manifest) {
|
|
122
|
-
const manifestCopy = manifest.clone();
|
|
123
|
-
delete manifestCopy.result.source.shasum;
|
|
124
|
-
// We use fast-json-stable-stringify to deterministically serialize the JSON
|
|
125
|
-
// This is required before checksumming so we get reproducible checksums across platforms etc
|
|
126
|
-
manifestCopy.value = (0, _fastjsonstablestringify.default)(manifestCopy.result);
|
|
127
|
-
return manifestCopy;
|
|
128
|
-
}
|
|
129
|
-
function getSnapChecksum(files) {
|
|
130
|
-
const { manifest, sourceCode, svgIcon } = files;
|
|
131
|
-
const all = [
|
|
132
|
-
getChecksummableManifest(manifest),
|
|
133
|
-
sourceCode,
|
|
134
|
-
svgIcon
|
|
135
|
-
].filter((file)=>file !== undefined);
|
|
136
|
-
return _base.base64.encode((0, _checksum.checksumFiles)(all));
|
|
137
|
-
}
|
|
138
|
-
function validateSnapShasum(files, errorMessage = 'Invalid Snap manifest: manifest shasum does not match computed shasum.') {
|
|
139
|
-
if (files.manifest.result.source.shasum !== getSnapChecksum(files)) {
|
|
140
|
-
throw new ProgrammaticallyFixableSnapError(errorMessage, _types.SnapValidationFailureReason.ShasumMismatch);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const LOCALHOST_HOSTNAMES = [
|
|
144
|
-
'localhost',
|
|
145
|
-
'127.0.0.1',
|
|
146
|
-
'[::1]'
|
|
147
|
-
];
|
|
148
|
-
const BaseSnapIdStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), /^[\x21-\x7E]*$/u);
|
|
149
|
-
const LocalSnapIdSubUrlStruct = (0, _types.uri)({
|
|
150
|
-
protocol: (0, _superstruct.enums)([
|
|
151
|
-
'http:',
|
|
152
|
-
'https:'
|
|
153
|
-
]),
|
|
154
|
-
hostname: (0, _superstruct.enums)(LOCALHOST_HOSTNAMES),
|
|
155
|
-
hash: (0, _superstruct.empty)((0, _superstruct.string)()),
|
|
156
|
-
search: (0, _superstruct.empty)((0, _superstruct.string)())
|
|
157
|
-
});
|
|
158
|
-
const LocalSnapIdStruct = (0, _superstruct.refine)(BaseSnapIdStruct, 'local Snap Id', (value)=>{
|
|
159
|
-
if (!value.startsWith(_types.SnapIdPrefixes.local)) {
|
|
160
|
-
return `Expected local snap ID, got "${value}".`;
|
|
161
|
-
}
|
|
162
|
-
const [error] = (0, _superstruct.validate)(value.slice(_types.SnapIdPrefixes.local.length), LocalSnapIdSubUrlStruct);
|
|
163
|
-
return error ?? true;
|
|
164
|
-
});
|
|
165
|
-
const NpmSnapIdStruct = (0, _superstruct.intersection)([
|
|
166
|
-
BaseSnapIdStruct,
|
|
167
|
-
(0, _types.uri)({
|
|
168
|
-
protocol: (0, _superstruct.literal)(_types.SnapIdPrefixes.npm),
|
|
169
|
-
pathname: (0, _superstruct.refine)((0, _superstruct.string)(), 'package name', function*(value) {
|
|
170
|
-
const normalized = value.startsWith('/') ? value.slice(1) : value;
|
|
171
|
-
const { errors, validForNewPackages, warnings } = (0, _validatenpmpackagename.default)(normalized);
|
|
172
|
-
if (!validForNewPackages) {
|
|
173
|
-
if (errors === undefined) {
|
|
174
|
-
(0, _utils.assert)(warnings !== undefined);
|
|
175
|
-
yield* warnings;
|
|
176
|
-
} else {
|
|
177
|
-
yield* errors;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return true;
|
|
181
|
-
}),
|
|
182
|
-
search: (0, _superstruct.empty)((0, _superstruct.string)()),
|
|
183
|
-
hash: (0, _superstruct.empty)((0, _superstruct.string)())
|
|
184
|
-
})
|
|
185
|
-
]);
|
|
186
|
-
const HttpSnapIdStruct = (0, _superstruct.intersection)([
|
|
187
|
-
BaseSnapIdStruct,
|
|
188
|
-
(0, _types.uri)({
|
|
189
|
-
protocol: (0, _superstruct.enums)([
|
|
190
|
-
'http:',
|
|
191
|
-
'https:'
|
|
192
|
-
]),
|
|
193
|
-
search: (0, _superstruct.empty)((0, _superstruct.string)()),
|
|
194
|
-
hash: (0, _superstruct.empty)((0, _superstruct.string)())
|
|
195
|
-
})
|
|
196
|
-
]);
|
|
197
|
-
const SnapIdStruct = (0, _superstruct.union)([
|
|
198
|
-
NpmSnapIdStruct,
|
|
199
|
-
LocalSnapIdStruct
|
|
200
|
-
]);
|
|
201
|
-
function getSnapPrefix(snapId) {
|
|
202
|
-
const prefix = Object.values(_types.SnapIdPrefixes).find((possiblePrefix)=>snapId.startsWith(possiblePrefix));
|
|
203
|
-
if (prefix !== undefined) {
|
|
204
|
-
return prefix;
|
|
205
|
-
}
|
|
206
|
-
throw new Error(`Invalid or no prefix found for "${snapId}"`);
|
|
207
|
-
}
|
|
208
|
-
function stripSnapPrefix(snapId) {
|
|
209
|
-
return snapId.replace(getSnapPrefix(snapId), '');
|
|
210
|
-
}
|
|
211
|
-
function assertIsValidSnapId(value) {
|
|
212
|
-
(0, _utils.assertStruct)(value, SnapIdStruct, 'Invalid snap ID');
|
|
213
|
-
}
|
|
214
|
-
function isCaipChainId(chainId) {
|
|
215
|
-
return typeof chainId === 'string' && RegExp("^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$", "u").test(chainId);
|
|
216
|
-
}
|
|
217
|
-
function isSnapPermitted(permissions, snapId) {
|
|
218
|
-
return Boolean((permissions?.wallet_snap?.caveats?.find((caveat)=>caveat.type === _caveats.SnapCaveatType.SnapIds) ?? {}).value?.[snapId]);
|
|
219
|
-
}
|
|
220
|
-
function verifyRequestedSnapPermissions(requestedPermissions) {
|
|
221
|
-
(0, _utils.assert)((0, _utils.isObject)(requestedPermissions), 'Requested permissions must be an object.');
|
|
222
|
-
const { wallet_snap: walletSnapPermission } = requestedPermissions;
|
|
223
|
-
(0, _utils.assert)((0, _utils.isObject)(walletSnapPermission), 'wallet_snap is missing from the requested permissions.');
|
|
224
|
-
const { caveats } = walletSnapPermission;
|
|
225
|
-
(0, _utils.assert)(Array.isArray(caveats) && caveats.length === 1, 'wallet_snap must have a caveat property with a single-item array value.');
|
|
226
|
-
const [caveat] = caveats;
|
|
227
|
-
(0, _utils.assert)((0, _utils.isObject)(caveat) && caveat.type === _caveats.SnapCaveatType.SnapIds && (0, _utils.isObject)(caveat.value), `The requested permissions do not have a valid ${_caveats.SnapCaveatType.SnapIds} caveat.`);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
//# sourceMappingURL=snaps.js.map
|
package/dist/cjs/snaps.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/snaps.ts"],"sourcesContent":["import {\n Caveat,\n SubjectPermissions,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport { BlockReason } from '@metamask/snaps-registry';\nimport {\n assert,\n Json,\n SemVerVersion,\n isObject,\n Opaque,\n assertStruct,\n} from '@metamask/utils';\nimport { base64 } from '@scure/base';\nimport { SerializedEthereumRpcError } from 'eth-rpc-errors/dist/classes';\nimport stableStringify from 'fast-json-stable-stringify';\nimport {\n empty,\n enums,\n intersection,\n literal,\n pattern,\n refine,\n string,\n Struct,\n union,\n validate,\n} from 'superstruct';\nimport validateNPMPackage from 'validate-npm-package-name';\n\nimport { SnapCaveatType } from './caveats';\nimport { checksumFiles } from './checksum';\nimport { SnapManifest, SnapPermissions } from './manifest/validation';\nimport {\n SnapFiles,\n SnapId,\n SnapIdPrefixes,\n SnapsPermissionRequest,\n SnapValidationFailureReason,\n uri,\n} from './types';\nimport { VirtualFile } from './virtual-file';\n\n// This RegEx matches valid npm package names (with some exceptions) and space-\n// separated alphanumerical words, optionally with dashes and underscores.\n// The RegEx consists of two parts. The first part matches space-separated\n// words. It is based on the following Stackoverflow answer:\n// https://stackoverflow.com/a/34974982\n// The second part, after the pipe operator, is the same RegEx used for the\n// `name` field of the official package.json JSON Schema, except that we allow\n// mixed-case letters. It was originally copied from:\n// https://github.com/SchemaStore/schemastore/blob/81a16897c1dabfd98c72242a5fd62eb080ff76d8/src/schemas/json/package.json#L132-L138\nexport const PROPOSED_NAME_REGEX =\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u;\n\n/**\n * wallet_enable / wallet_installSnaps permission typing.\n *\n * @deprecated This type is confusing and not descriptive, people confused it with typing initialPermissions, remove when removing wallet_enable.\n */\nexport type RequestedSnapPermissions = {\n [permission: string]: Record<string, Json>;\n};\n\nexport enum SnapStatus {\n Installing = 'installing',\n Updating = 'updating',\n Running = 'running',\n Stopped = 'stopped',\n Crashed = 'crashed',\n}\n\nexport enum SnapStatusEvents {\n Start = 'START',\n Stop = 'STOP',\n Crash = 'CRASH',\n Update = 'UPDATE',\n}\n\nexport type StatusContext = { snapId: ValidatedSnapId };\nexport type StatusEvents = { type: SnapStatusEvents };\nexport type StatusStates = {\n value: SnapStatus;\n context: StatusContext;\n};\nexport type Status = StatusStates['value'];\n\nexport type VersionHistory = {\n origin: string;\n version: string;\n // Unix timestamp\n date: number;\n};\n\nexport type PersistedSnap = Snap & {\n /**\n * The source code of the Snap.\n */\n sourceCode: string;\n};\n\n/**\n * A Snap as it exists in {@link SnapController} state.\n */\nexport type Snap = {\n /**\n * Whether the Snap is enabled, which determines if it can be started.\n */\n enabled: boolean;\n\n /**\n * The ID of the Snap.\n */\n id: ValidatedSnapId;\n\n /**\n * The initial permissions of the Snap, which will be requested when it is\n * installed.\n */\n initialPermissions: SnapPermissions;\n\n /**\n * The Snap's manifest file.\n */\n manifest: SnapManifest;\n\n /**\n * Whether the Snap is blocked.\n */\n blocked: boolean;\n\n /**\n * Information detailing why the snap is blocked.\n */\n blockInformation?: BlockReason;\n\n /**\n * The current status of the Snap, e.g. whether it's running or stopped.\n */\n status: Status;\n\n /**\n * The version of the Snap.\n */\n version: SemVerVersion;\n\n /**\n * The version history of the Snap.\n * Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.\n */\n versionHistory: VersionHistory[];\n};\n\nexport type TruncatedSnapFields =\n | 'id'\n | 'initialPermissions'\n | 'version'\n | 'enabled'\n | 'blocked';\n\n/**\n * A {@link Snap} object with the fields that are relevant to an external\n * caller.\n */\nexport type TruncatedSnap = Pick<Snap, TruncatedSnapFields>;\n\nexport type ProcessSnapResult =\n | TruncatedSnap\n | { error: SerializedEthereumRpcError };\n\nexport type InstallSnapsResult = Record<SnapId, ProcessSnapResult>;\n\n/**\n * An error indicating that a Snap validation failure is programmatically\n * fixable during development.\n */\nexport class ProgrammaticallyFixableSnapError extends Error {\n reason: SnapValidationFailureReason;\n\n constructor(message: string, reason: SnapValidationFailureReason) {\n super(message);\n this.reason = reason;\n }\n}\n\n/**\n * Gets a checksummable manifest by removing the shasum property and reserializing the JSON using a deterministic algorithm.\n *\n * @param manifest - The manifest itself.\n * @returns A virtual file containing the checksummable manifest.\n */\nfunction getChecksummableManifest(\n manifest: VirtualFile<SnapManifest>,\n): VirtualFile {\n const manifestCopy = manifest.clone() as VirtualFile<any>;\n delete manifestCopy.result.source.shasum;\n\n // We use fast-json-stable-stringify to deterministically serialize the JSON\n // This is required before checksumming so we get reproducible checksums across platforms etc\n manifestCopy.value = stableStringify(manifestCopy.result);\n return manifestCopy;\n}\n\n/**\n * Calculates the Base64-encoded SHA-256 digest of all required Snap files.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @returns The Base64-encoded SHA-256 digest of the source code.\n */\nexport function getSnapChecksum(\n files: Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon'>,\n): string {\n const { manifest, sourceCode, svgIcon } = files;\n const all = [getChecksummableManifest(manifest), sourceCode, svgIcon].filter(\n (file) => file !== undefined,\n );\n return base64.encode(checksumFiles(all as VirtualFile[]));\n}\n\n/**\n * Checks whether the `source.shasum` property of a Snap manifest matches the\n * shasum of the snap.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @param errorMessage - The error message to throw if validation fails.\n */\nexport function validateSnapShasum(\n files: Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon'>,\n errorMessage = 'Invalid Snap manifest: manifest shasum does not match computed shasum.',\n): void {\n if (files.manifest.result.source.shasum !== getSnapChecksum(files)) {\n throw new ProgrammaticallyFixableSnapError(\n errorMessage,\n SnapValidationFailureReason.ShasumMismatch,\n );\n }\n}\n\nexport const LOCALHOST_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]'] as const;\n\n// Require snap ids to only consist of printable ASCII characters\nexport const BaseSnapIdStruct = pattern(string(), /^[\\x21-\\x7E]*$/u);\n\nconst LocalSnapIdSubUrlStruct = uri({\n protocol: enums(['http:', 'https:']),\n hostname: enums(LOCALHOST_HOSTNAMES),\n hash: empty(string()),\n search: empty(string()),\n});\nexport const LocalSnapIdStruct = refine(\n BaseSnapIdStruct,\n 'local Snap Id',\n (value) => {\n if (!value.startsWith(SnapIdPrefixes.local)) {\n return `Expected local snap ID, got \"${value}\".`;\n }\n\n const [error] = validate(\n value.slice(SnapIdPrefixes.local.length),\n LocalSnapIdSubUrlStruct,\n );\n return error ?? true;\n },\n);\nexport const NpmSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: literal(SnapIdPrefixes.npm),\n pathname: refine(string(), 'package name', function* (value) {\n const normalized = value.startsWith('/') ? value.slice(1) : value;\n const { errors, validForNewPackages, warnings } =\n validateNPMPackage(normalized);\n if (!validForNewPackages) {\n if (errors === undefined) {\n assert(warnings !== undefined);\n yield* warnings;\n } else {\n yield* errors;\n }\n }\n return true;\n }),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const HttpSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: enums(['http:', 'https:']),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const SnapIdStruct = union([NpmSnapIdStruct, LocalSnapIdStruct]);\n\nexport type ValidatedSnapId = Opaque<string, typeof snapIdSymbol>;\ndeclare const snapIdSymbol: unique symbol;\n\n/**\n * Extracts the snap prefix from a snap ID.\n *\n * @param snapId - The snap ID to extract the prefix from.\n * @returns The snap prefix from a snap id, e.g. `npm:`.\n */\nexport function getSnapPrefix(snapId: string): SnapIdPrefixes {\n const prefix = Object.values(SnapIdPrefixes).find((possiblePrefix) =>\n snapId.startsWith(possiblePrefix),\n );\n if (prefix !== undefined) {\n return prefix;\n }\n throw new Error(`Invalid or no prefix found for \"${snapId}\"`);\n}\n\n/**\n * Strips snap prefix from a full snap ID.\n *\n * @param snapId - The snap ID to strip.\n * @returns The stripped snap ID.\n */\nexport function stripSnapPrefix(snapId: string): string {\n return snapId.replace(getSnapPrefix(snapId), '');\n}\n\n/**\n * Assert that the given value is a valid snap ID.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid snap ID.\n */\nexport function assertIsValidSnapId(\n value: unknown,\n): asserts value is ValidatedSnapId {\n assertStruct(value, SnapIdStruct, 'Invalid snap ID');\n}\n\n/**\n * Typeguard to ensure a chainId follows the CAIP-2 standard.\n *\n * @param chainId - The chainId being tested.\n * @returns `true` if the value is a valid CAIP chain id, and `false` otherwise.\n */\nexport function isCaipChainId(chainId: unknown): chainId is string {\n return (\n typeof chainId === 'string' &&\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u.test(\n chainId,\n )\n );\n}\n\n/**\n * Utility function to check if an origin has permission (and caveat) for a particular snap.\n *\n * @param permissions - An origin's permissions object.\n * @param snapId - The id of the snap.\n * @returns A boolean based on if an origin has the specified snap.\n */\nexport function isSnapPermitted(\n permissions: SubjectPermissions<PermissionConstraint>,\n snapId: SnapId,\n) {\n return Boolean(\n (\n (\n (permissions?.wallet_snap?.caveats?.find(\n (caveat) => caveat.type === SnapCaveatType.SnapIds,\n ) ?? {}) as Caveat<string, Json>\n ).value as Record<string, unknown>\n )?.[snapId],\n );\n}\n\n/**\n * Checks whether the passed in requestedPermissions is a valid\n * permission request for a `wallet_snap` permission.\n *\n * @param requestedPermissions - The requested permissions.\n * @throws If the criteria is not met.\n */\nexport function verifyRequestedSnapPermissions(\n requestedPermissions: unknown,\n): asserts requestedPermissions is SnapsPermissionRequest {\n assert(\n isObject(requestedPermissions),\n 'Requested permissions must be an object.',\n );\n\n const { wallet_snap: walletSnapPermission } = requestedPermissions;\n\n assert(\n isObject(walletSnapPermission),\n 'wallet_snap is missing from the requested permissions.',\n );\n\n const { caveats } = walletSnapPermission;\n\n assert(\n Array.isArray(caveats) && caveats.length === 1,\n 'wallet_snap must have a caveat property with a single-item array value.',\n );\n\n const [caveat] = caveats;\n\n assert(\n isObject(caveat) &&\n caveat.type === SnapCaveatType.SnapIds &&\n isObject(caveat.value),\n `The requested permissions do not have a valid ${SnapCaveatType.SnapIds} caveat.`,\n );\n}\n"],"names":["PROPOSED_NAME_REGEX","ProgrammaticallyFixableSnapError","getSnapChecksum","validateSnapShasum","LOCALHOST_HOSTNAMES","BaseSnapIdStruct","LocalSnapIdStruct","NpmSnapIdStruct","HttpSnapIdStruct","SnapIdStruct","getSnapPrefix","stripSnapPrefix","assertIsValidSnapId","isCaipChainId","isSnapPermitted","verifyRequestedSnapPermissions","SnapStatus","Installing","Updating","Running","Stopped","Crashed","SnapStatusEvents","Start","Stop","Crash","Update","Error","constructor","message","reason","getChecksummableManifest","manifest","manifestCopy","clone","result","source","shasum","value","stableStringify","files","sourceCode","svgIcon","all","filter","file","undefined","base64","encode","checksumFiles","errorMessage","SnapValidationFailureReason","ShasumMismatch","pattern","string","LocalSnapIdSubUrlStruct","uri","protocol","enums","hostname","hash","empty","search","refine","startsWith","SnapIdPrefixes","local","error","validate","slice","length","intersection","literal","npm","pathname","normalized","errors","validForNewPackages","warnings","validateNPMPackage","assert","union","snapId","prefix","Object","values","find","possiblePrefix","replace","assertStruct","chainId","test","permissions","Boolean","wallet_snap","caveats","caveat","type","SnapCaveatType","SnapIds","requestedPermissions","isObject","walletSnapPermission","Array","isArray"],"mappings":"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"}
|
package/dist/cjs/types.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
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
|
-
NpmSnapFileNames: function() {
|
|
13
|
-
return NpmSnapFileNames;
|
|
14
|
-
},
|
|
15
|
-
SnapIdPrefixes: function() {
|
|
16
|
-
return SnapIdPrefixes;
|
|
17
|
-
},
|
|
18
|
-
SnapValidationFailureReason: function() {
|
|
19
|
-
return SnapValidationFailureReason;
|
|
20
|
-
},
|
|
21
|
-
SNAP_STREAM_NAMES: function() {
|
|
22
|
-
return SNAP_STREAM_NAMES;
|
|
23
|
-
},
|
|
24
|
-
HandlerType: function() {
|
|
25
|
-
return HandlerType;
|
|
26
|
-
},
|
|
27
|
-
NameStruct: function() {
|
|
28
|
-
return NameStruct;
|
|
29
|
-
},
|
|
30
|
-
NpmSnapPackageJsonStruct: function() {
|
|
31
|
-
return NpmSnapPackageJsonStruct;
|
|
32
|
-
},
|
|
33
|
-
isNpmSnapPackageJson: function() {
|
|
34
|
-
return isNpmSnapPackageJson;
|
|
35
|
-
},
|
|
36
|
-
assertIsNpmSnapPackageJson: function() {
|
|
37
|
-
return assertIsNpmSnapPackageJson;
|
|
38
|
-
},
|
|
39
|
-
SNAP_EXPORT_NAMES: function() {
|
|
40
|
-
return SNAP_EXPORT_NAMES;
|
|
41
|
-
},
|
|
42
|
-
uri: function() {
|
|
43
|
-
return uri;
|
|
44
|
-
},
|
|
45
|
-
isValidUrl: function() {
|
|
46
|
-
return isValidUrl;
|
|
47
|
-
},
|
|
48
|
-
WALLET_SNAP_PERMISSION_KEY: function() {
|
|
49
|
-
return WALLET_SNAP_PERMISSION_KEY;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const _utils = require("@metamask/utils");
|
|
53
|
-
const _superstruct = require("superstruct");
|
|
54
|
-
var NpmSnapFileNames;
|
|
55
|
-
(function(NpmSnapFileNames) {
|
|
56
|
-
NpmSnapFileNames["PackageJson"] = 'package.json';
|
|
57
|
-
NpmSnapFileNames["Manifest"] = 'snap.manifest.json';
|
|
58
|
-
})(NpmSnapFileNames || (NpmSnapFileNames = {}));
|
|
59
|
-
const NameStruct = (0, _superstruct.size)((0, _superstruct.pattern)((0, _superstruct.string)(), /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u), 1, 214);
|
|
60
|
-
const NpmSnapPackageJsonStruct = (0, _superstruct.type)({
|
|
61
|
-
version: _utils.VersionStruct,
|
|
62
|
-
name: NameStruct,
|
|
63
|
-
main: (0, _superstruct.optional)((0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity)),
|
|
64
|
-
repository: (0, _superstruct.optional)((0, _superstruct.object)({
|
|
65
|
-
type: (0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity),
|
|
66
|
-
url: (0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity)
|
|
67
|
-
}))
|
|
68
|
-
});
|
|
69
|
-
function isNpmSnapPackageJson(value) {
|
|
70
|
-
return (0, _superstruct.is)(value, NpmSnapPackageJsonStruct);
|
|
71
|
-
}
|
|
72
|
-
function assertIsNpmSnapPackageJson(value) {
|
|
73
|
-
(0, _utils.assertStruct)(value, NpmSnapPackageJsonStruct, `"${NpmSnapFileNames.PackageJson}" is invalid`);
|
|
74
|
-
}
|
|
75
|
-
var SnapIdPrefixes;
|
|
76
|
-
(function(SnapIdPrefixes) {
|
|
77
|
-
SnapIdPrefixes["npm"] = 'npm:';
|
|
78
|
-
SnapIdPrefixes["local"] = 'local:';
|
|
79
|
-
})(SnapIdPrefixes || (SnapIdPrefixes = {}));
|
|
80
|
-
var SnapValidationFailureReason;
|
|
81
|
-
(function(SnapValidationFailureReason) {
|
|
82
|
-
SnapValidationFailureReason["NameMismatch"] = '"name" field mismatch';
|
|
83
|
-
SnapValidationFailureReason["VersionMismatch"] = '"version" field mismatch';
|
|
84
|
-
SnapValidationFailureReason["RepositoryMismatch"] = '"repository" field mismatch';
|
|
85
|
-
SnapValidationFailureReason["ShasumMismatch"] = '"shasum" field mismatch';
|
|
86
|
-
})(SnapValidationFailureReason || (SnapValidationFailureReason = {}));
|
|
87
|
-
var SNAP_STREAM_NAMES;
|
|
88
|
-
(function(SNAP_STREAM_NAMES) {
|
|
89
|
-
SNAP_STREAM_NAMES["JSON_RPC"] = 'jsonRpc';
|
|
90
|
-
SNAP_STREAM_NAMES["COMMAND"] = 'command';
|
|
91
|
-
})(SNAP_STREAM_NAMES || (SNAP_STREAM_NAMES = {}));
|
|
92
|
-
var HandlerType;
|
|
93
|
-
(function(HandlerType) {
|
|
94
|
-
HandlerType["OnRpcRequest"] = 'onRpcRequest';
|
|
95
|
-
HandlerType["OnTransaction"] = 'onTransaction';
|
|
96
|
-
HandlerType["OnCronjob"] = 'onCronjob';
|
|
97
|
-
})(HandlerType || (HandlerType = {}));
|
|
98
|
-
const SNAP_EXPORT_NAMES = Object.values(HandlerType);
|
|
99
|
-
const uri = (opts = {})=>(0, _superstruct.refine)((0, _superstruct.union)([
|
|
100
|
-
(0, _superstruct.string)(),
|
|
101
|
-
(0, _superstruct.instance)(URL)
|
|
102
|
-
]), 'uri', (value)=>{
|
|
103
|
-
try {
|
|
104
|
-
const url = new URL(value);
|
|
105
|
-
const UrlStruct = (0, _superstruct.type)(opts);
|
|
106
|
-
(0, _superstruct.assert)(url, UrlStruct);
|
|
107
|
-
return true;
|
|
108
|
-
} catch {
|
|
109
|
-
return `Expected URL, got "${value.toString()}".`;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
function isValidUrl(url, opts = {}) {
|
|
113
|
-
return (0, _superstruct.is)(url, uri(opts));
|
|
114
|
-
}
|
|
115
|
-
const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';
|
|
116
|
-
|
|
117
|
-
//# sourceMappingURL=types.js.map
|
package/dist/cjs/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import { assertStruct, Json, VersionStruct } from '@metamask/utils';\nimport {\n Infer,\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n Struct,\n type,\n union,\n assert as assertSuperstruct,\n} from 'superstruct';\n\nimport { SnapCaveatType } from './caveats';\nimport { SnapFunctionExports } from './handlers';\nimport { SnapManifest } from './manifest';\nimport { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n pattern(\n string(),\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * Check if the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link NpmSnapPackageJson} object.\n */\nexport function isNpmSnapPackageJson(\n value: unknown,\n): value is NpmSnapPackageJson {\n return is(value, NpmSnapPackageJsonStruct);\n}\n\n/**\n * Asserts that the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link NpmSnapPackageJson} object.\n */\nexport function assertIsNpmSnapPackageJson(\n value: unknown,\n): asserts value is NpmSnapPackageJson {\n assertStruct(\n value,\n NpmSnapPackageJsonStruct,\n `\"${NpmSnapFileNames.PackageJson}\" is invalid`,\n );\n}\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n};\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapId = string;\n\n/**\n * Snap validation failure reason codes that are programmatically fixable\n * if validation occurs during development.\n */\nexport enum SnapValidationFailureReason {\n NameMismatch = '\"name\" field mismatch',\n VersionMismatch = '\"version\" field mismatch',\n RepositoryMismatch = '\"repository\" field mismatch',\n ShasumMismatch = '\"shasum\" field mismatch',\n}\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnTransaction = 'onTransaction',\n OnCronjob = 'onCronjob',\n}\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<T extends string> = {\n protocol?: Struct<T>;\n hash?: Struct<T>;\n port?: Struct<T>;\n hostname?: Struct<T>;\n pathname?: Struct<T>;\n search?: Struct<T>;\n};\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(union([string(), instance(URL)]), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch {\n return `Expected URL, got \"${value.toString()}\".`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string | URL {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"],"names":["NameStruct","NpmSnapPackageJsonStruct","isNpmSnapPackageJson","assertIsNpmSnapPackageJson","SNAP_EXPORT_NAMES","uri","isValidUrl","WALLET_SNAP_PERMISSION_KEY","NpmSnapFileNames","PackageJson","Manifest","size","pattern","string","type","version","VersionStruct","name","main","optional","Infinity","repository","object","url","value","is","assertStruct","SnapIdPrefixes","npm","local","SnapValidationFailureReason","NameMismatch","VersionMismatch","RepositoryMismatch","ShasumMismatch","SNAP_STREAM_NAMES","JSON_RPC","COMMAND","HandlerType","OnRpcRequest","OnTransaction","OnCronjob","Object","values","opts","refine","union","instance","URL","UrlStruct","assertSuperstruct","toString"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;IA2BaA,UAAU;eAAVA;;IAWAC,wBAAwB;eAAxBA;;IAqBGC,oBAAoB;eAApBA;;IAYAC,0BAA0B;eAA1BA;;IAmEHC,iBAAiB;eAAjBA;;IAyBAC,GAAG;eAAHA;;IAoBGC,UAAU;eAAVA;;IAQHC,0BAA0B;eAA1BA;;;uBA/LqC;6BAe3C;IAOA;UAAKC,gBAAgB;IAAhBA,iBACVC,iBAAc;IADJD,iBAEVE,cAAW;GAFDF,qBAAAA;AAKL,MAAMR,aAAaW,IAAAA,iBAAI,EAC5BC,IAAAA,oBAAO,EACLC,IAAAA,mBAAM,KACN,gEAEF,GACA;AAKK,MAAMZ,2BAA2Ba,IAAAA,iBAAI,EAAC;IAC3CC,SAASC,oBAAa;IACtBC,MAAMjB;IACNkB,MAAMC,IAAAA,qBAAQ,EAACR,IAAAA,iBAAI,EAACE,IAAAA,mBAAM,KAAI,GAAGO;IACjCC,YAAYF,IAAAA,qBAAQ,EAClBG,IAAAA,mBAAM,EAAC;QACLR,MAAMH,IAAAA,iBAAI,EAACE,IAAAA,mBAAM,KAAI,GAAGO;QACxBG,KAAKZ,IAAAA,iBAAI,EAACE,IAAAA,mBAAM,KAAI,GAAGO;IACzB;AAEJ;AAWO,SAASlB,qBACdsB,KAAc;IAEd,OAAOC,IAAAA,eAAE,EAACD,OAAOvB;AACnB;AAQO,SAASE,2BACdqB,KAAc;IAEdE,IAAAA,mBAAY,EACVF,OACAvB,0BACA,CAAC,CAAC,EAAEO,iBAAiBC,WAAW,CAAC,YAAY,CAAC;AAElD;IA2BO;UAAKkB,cAAc;IAAdA,eACVC,SAAM;IADID,eAEVE,WAAQ;GAFEF,mBAAAA;IAYL;UAAKG,2BAA2B;IAA3BA,4BACVC,kBAAe;IADLD,4BAEVE,qBAAkB;IAFRF,4BAGVG,wBAAqB;IAHXH,4BAIVI,oBAAiB;GAJPJ,gCAAAA;IAQL;UAAKK,iBAAiB;IAAjBA,kBACVC,cAAW;IADDD,kBAEVE,aAAU;GAFAF,sBAAAA;IAML;UAAKG,WAAW;IAAXA,YACVC,kBAAe;IADLD,YAEVE,mBAAgB;IAFNF,YAGVG,eAAY;GAHFH,gBAAAA;AAML,MAAMlC,oBAAoBsC,OAAOC,MAAM,CAACL;AAyBxC,MAAMjC,MAAM,CAACuC,OAAwB,CAAC,CAAC,GAC5CC,IAAAA,mBAAM,EAACC,IAAAA,kBAAK,EAAC;QAACjC,IAAAA,mBAAM;QAAIkC,IAAAA,qBAAQ,EAACC;KAAK,GAAG,OAAO,CAACxB;QAC/C,IAAI;YACF,MAAMD,MAAM,IAAIyB,IAAIxB;YAEpB,MAAMyB,YAAYnC,IAAAA,iBAAI,EAAC8B;YACvBM,IAAAA,mBAAiB,EAAC3B,KAAK0B;YACvB,OAAO;QACT,EAAE,OAAM;YACN,OAAO,CAAC,mBAAmB,EAAEzB,MAAM2B,QAAQ,GAAG,EAAE,CAAC;QACnD;IACF;AASK,SAAS7C,WACdiB,GAAY,EACZqB,OAAwB,CAAC,CAAC;IAE1B,OAAOnB,IAAAA,eAAE,EAACF,KAAKlB,IAAIuC;AACrB;AAGO,MAAMrC,6BAA6B"}
|
package/dist/cjs/validation.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "validateFetchedSnap", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return validateFetchedSnap;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _icon = require("./icon");
|
|
12
|
-
const _validation = require("./manifest/validation");
|
|
13
|
-
const _snaps = require("./snaps");
|
|
14
|
-
function validateFetchedSnap(files) {
|
|
15
|
-
(0, _validation.assertIsSnapManifest)(files.manifest.result);
|
|
16
|
-
(0, _snaps.validateSnapShasum)(files);
|
|
17
|
-
if (files.svgIcon) {
|
|
18
|
-
(0, _icon.assertIsSnapIcon)(files.svgIcon);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/validation.ts"],"sourcesContent":["import { assertIsSnapIcon } from './icon';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport { validateSnapShasum } from './snaps';\nimport { SnapFiles } from './types';\n\n/**\n * Validates the files contained in a fetched snap.\n *\n * @param files - All potentially included files in a fetched snap.\n * @throws If any of the files are considered invalid.\n */\nexport function validateFetchedSnap(\n files: Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon'>,\n): void {\n assertIsSnapManifest(files.manifest.result);\n validateSnapShasum(files);\n\n if (files.svgIcon) {\n assertIsSnapIcon(files.svgIcon);\n }\n}\n"],"names":["validateFetchedSnap","files","assertIsSnapManifest","manifest","result","validateSnapShasum","svgIcon","assertIsSnapIcon"],"mappings":";;;;+BAWgBA;;;eAAAA;;;sBAXiB;4BACI;uBACF;AAS5B,SAASA,oBACdC,KAA6D;IAE7DC,IAAAA,gCAAoB,EAACD,MAAME,QAAQ,CAACC,MAAM;IAC1CC,IAAAA,yBAAkB,EAACJ;IAEnB,IAAIA,MAAMK,OAAO,EAAE;QACjBC,IAAAA,sBAAgB,EAACN,MAAMK,OAAO;IAChC;AACF"}
|
package/dist/cjs/versions.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
DEFAULT_REQUESTED_SNAP_VERSION: function() {
|
|
13
|
-
return DEFAULT_REQUESTED_SNAP_VERSION;
|
|
14
|
-
},
|
|
15
|
-
getTargetVersion: function() {
|
|
16
|
-
return getTargetVersion;
|
|
17
|
-
},
|
|
18
|
-
resolveVersionRange: function() {
|
|
19
|
-
return resolveVersionRange;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _utils = require("@metamask/utils");
|
|
23
|
-
const _semver = require("semver");
|
|
24
|
-
const _superstruct = require("superstruct");
|
|
25
|
-
const DEFAULT_REQUESTED_SNAP_VERSION = '*';
|
|
26
|
-
function getTargetVersion(versions, versionRange) {
|
|
27
|
-
const maxSatisfyingNonPreRelease = (0, _semver.maxSatisfying)(versions, versionRange);
|
|
28
|
-
// By default don't use pre-release versions
|
|
29
|
-
if (maxSatisfyingNonPreRelease) {
|
|
30
|
-
return maxSatisfyingNonPreRelease;
|
|
31
|
-
}
|
|
32
|
-
// If no satisfying release version is found by default, try pre-release versions
|
|
33
|
-
return (0, _semver.maxSatisfying)(versions, versionRange, {
|
|
34
|
-
includePrerelease: true
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function resolveVersionRange(version) {
|
|
38
|
-
if (version === undefined || version === 'latest') {
|
|
39
|
-
return [
|
|
40
|
-
undefined,
|
|
41
|
-
DEFAULT_REQUESTED_SNAP_VERSION
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
return (0, _superstruct.validate)(version, _utils.VersionRangeStruct);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=versions.js.map
|
package/dist/cjs/versions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/versions.ts"],"sourcesContent":["import {\n Json,\n SemVerVersion,\n SemVerRange,\n VersionRangeStruct,\n} from '@metamask/utils';\nimport { maxSatisfying as maxSatisfyingSemver } from 'semver';\nimport { validate } from 'superstruct';\n\nexport const DEFAULT_REQUESTED_SNAP_VERSION = '*' as SemVerRange;\n\n/**\n * Return the highest version in the list that satisfies the range, or `null` if\n * none of them do. For the satisfaction check, pre-release versions will only\n * be checked if no satisfactory non-prerelease version is found first.\n *\n * @param versions - The list of version to check.\n * @param versionRange - The SemVer version range to check against.\n * @returns The highest version in the list that satisfies the range,\n * or `null` if none of them do.\n */\nexport function getTargetVersion(\n versions: SemVerVersion[],\n versionRange: SemVerRange,\n): SemVerVersion | null {\n const maxSatisfyingNonPreRelease = maxSatisfyingSemver(\n versions,\n versionRange,\n );\n\n // By default don't use pre-release versions\n if (maxSatisfyingNonPreRelease) {\n return maxSatisfyingNonPreRelease;\n }\n\n // If no satisfying release version is found by default, try pre-release versions\n return maxSatisfyingSemver(versions, versionRange, {\n includePrerelease: true,\n });\n}\n\n/**\n * Parse a version received by some subject attempting to access a snap.\n *\n * @param version - The received version value.\n * @returns `*` if the version is `undefined` or `latest\", otherwise returns\n * the specified version.\n */\nexport function resolveVersionRange(\n version?: Json,\n): [error: undefined, range: SemVerRange] | [error: Error, range: undefined] {\n if (version === undefined || version === 'latest') {\n return [undefined, DEFAULT_REQUESTED_SNAP_VERSION];\n }\n return validate(version, VersionRangeStruct);\n}\n"],"names":["DEFAULT_REQUESTED_SNAP_VERSION","getTargetVersion","resolveVersionRange","versions","versionRange","maxSatisfyingNonPreRelease","maxSatisfyingSemver","includePrerelease","version","undefined","validate","VersionRangeStruct"],"mappings":";;;;;;;;;;;IASaA,8BAA8B;eAA9BA;;IAYGC,gBAAgB;eAAhBA;;IA2BAC,mBAAmB;eAAnBA;;;uBA3CT;wBAC8C;6BAC5B;AAElB,MAAMF,iCAAiC;AAYvC,SAASC,iBACdE,QAAyB,EACzBC,YAAyB;IAEzB,MAAMC,6BAA6BC,IAAAA,qBAAmB,EACpDH,UACAC;IAGF,4CAA4C;IAC5C,IAAIC,4BAA4B;QAC9B,OAAOA;IACT;IAEA,iFAAiF;IACjF,OAAOC,IAAAA,qBAAmB,EAACH,UAAUC,cAAc;QACjDG,mBAAmB;IACrB;AACF;AASO,SAASL,oBACdM,OAAc;IAEd,IAAIA,YAAYC,aAAaD,YAAY,UAAU;QACjD,OAAO;YAACC;YAAWT;SAA+B;IACpD;IACA,OAAOU,IAAAA,qBAAQ,EAACF,SAASG,yBAAkB;AAC7C"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review
|
|
2
|
-
// TODO(ritave): Streaming vfile contents similar to vinyl maybe?
|
|
3
|
-
// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile
|
|
4
|
-
// similar to unified instead of throwing "ProgrammaticallyFixableErrors".
|
|
5
|
-
//
|
|
6
|
-
// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.
|
|
7
|
-
// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because
|
|
8
|
-
// we're calculating checksums based on original path.
|
|
9
|
-
"use strict";
|
|
10
|
-
Object.defineProperty(exports, "__esModule", {
|
|
11
|
-
value: true
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(exports, "VirtualFile", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function() {
|
|
16
|
-
return VirtualFile;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _utils = require("@metamask/utils");
|
|
20
|
-
const _deepclone = require("../deep-clone");
|
|
21
|
-
function _define_property(obj, key, value) {
|
|
22
|
-
if (key in obj) {
|
|
23
|
-
Object.defineProperty(obj, key, {
|
|
24
|
-
value: value,
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
30
|
-
obj[key] = value;
|
|
31
|
-
}
|
|
32
|
-
return obj;
|
|
33
|
-
}
|
|
34
|
-
class VirtualFile {
|
|
35
|
-
toString(encoding) {
|
|
36
|
-
if (typeof this.value === 'string') {
|
|
37
|
-
(0, _utils.assert)(encoding === undefined, 'Tried to encode string.');
|
|
38
|
-
return this.value;
|
|
39
|
-
}
|
|
40
|
-
const decoder = new TextDecoder(encoding);
|
|
41
|
-
return decoder.decode(this.value);
|
|
42
|
-
}
|
|
43
|
-
clone() {
|
|
44
|
-
const vfile = new VirtualFile();
|
|
45
|
-
if (typeof this.value === 'string') {
|
|
46
|
-
vfile.value = this.value;
|
|
47
|
-
} else {
|
|
48
|
-
// deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array
|
|
49
|
-
vfile.value = this.value.slice(0);
|
|
50
|
-
}
|
|
51
|
-
vfile.result = (0, _deepclone.deepClone)(this.result);
|
|
52
|
-
vfile.data = (0, _deepclone.deepClone)(this.data);
|
|
53
|
-
vfile.path = this.path;
|
|
54
|
-
return vfile;
|
|
55
|
-
}
|
|
56
|
-
constructor(value){
|
|
57
|
-
_define_property(this, "value", void 0);
|
|
58
|
-
_define_property(this, "result", void 0);
|
|
59
|
-
_define_property(this, "data", void 0);
|
|
60
|
-
_define_property(this, "path", void 0);
|
|
61
|
-
let options;
|
|
62
|
-
if (typeof value === 'string' || value instanceof Uint8Array) {
|
|
63
|
-
options = {
|
|
64
|
-
value
|
|
65
|
-
};
|
|
66
|
-
} else {
|
|
67
|
-
options = value;
|
|
68
|
-
}
|
|
69
|
-
this.value = options?.value ?? '';
|
|
70
|
-
// This situations happens when there's no .result used,
|
|
71
|
-
// we expect the file to have default generic in that situation:
|
|
72
|
-
// VirtualFile<unknown> which will handle undefined properly
|
|
73
|
-
//
|
|
74
|
-
// While not 100% type safe, it'll be way less frustrating to work with.
|
|
75
|
-
// The alternative would be to have VirtualFile.result be Result | undefined
|
|
76
|
-
// and that would result in needing to branch out and check in all situations.
|
|
77
|
-
//
|
|
78
|
-
// In short, optimizing for most common use case.
|
|
79
|
-
this.result = options?.result ?? undefined;
|
|
80
|
-
this.data = options?.data ?? {};
|
|
81
|
-
this.path = options?.path ?? '/';
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
//# sourceMappingURL=VirtualFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/virtual-file/VirtualFile.ts"],"sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert } from '@metamask/utils';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-interface\nexport interface DataMap {}\n\nexport type Value = string | Uint8Array;\nexport type Compatible<Result = unknown> =\n | string\n | Uint8Array\n | Options<Result>;\nexport type Data = Record<string, unknown> & Partial<DataMap>;\nexport type Options<Result = unknown> = {\n value: Value;\n path?: string;\n data?: Data;\n result?: Result;\n};\n\nexport class VirtualFile<Result = unknown> {\n constructor(value?: Compatible<Result>) {\n let options: Options | undefined;\n if (typeof value === 'string' || value instanceof Uint8Array) {\n options = { value };\n } else {\n options = value;\n }\n\n this.value = options?.value ?? '';\n // This situations happens when there's no .result used,\n // we expect the file to have default generic in that situation:\n // VirtualFile<unknown> which will handle undefined properly\n //\n // While not 100% type safe, it'll be way less frustrating to work with.\n // The alternative would be to have VirtualFile.result be Result | undefined\n // and that would result in needing to branch out and check in all situations.\n //\n // In short, optimizing for most common use case.\n this.result = options?.result ?? (undefined as any);\n this.data = options?.data ?? {};\n this.path = options?.path ?? '/';\n }\n\n value: Value;\n\n result: Result;\n\n data: Data;\n\n path: string;\n\n toString(encoding?: string) {\n if (typeof this.value === 'string') {\n assert(encoding === undefined, 'Tried to encode string.');\n return this.value;\n }\n const decoder = new TextDecoder(encoding);\n return decoder.decode(this.value);\n }\n\n clone() {\n const vfile = new VirtualFile<Result>();\n if (typeof this.value === 'string') {\n vfile.value = this.value;\n } else {\n // deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array\n vfile.value = this.value.slice(0);\n }\n vfile.result = deepClone(this.result);\n vfile.data = deepClone(this.data);\n vfile.path = this.path;\n return vfile;\n }\n}\n"],"names":["VirtualFile","toString","encoding","value","assert","undefined","decoder","TextDecoder","decode","clone","vfile","slice","result","deepClone","data","path","constructor","options","Uint8Array"],"mappings":"AAAA,0HAA0H;AAC1H,iEAAiE;AACjE,2FAA2F;AAC3F,wFAAwF;AACxF,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AACrG,sDAAsD;;;;;+BAkCzCA;;;eAAAA;;;uBAjCU;2BAEG;;;;;;;;;;;;;;AA+BnB,MAAMA;IAgCXC,SAASC,QAAiB,EAAE;QAC1B,IAAI,OAAO,IAAI,CAACC,KAAK,KAAK,UAAU;YAClCC,IAAAA,aAAM,EAACF,aAAaG,WAAW;YAC/B,OAAO,IAAI,CAACF,KAAK;QACnB;QACA,MAAMG,UAAU,IAAIC,YAAYL;QAChC,OAAOI,QAAQE,MAAM,CAAC,IAAI,CAACL,KAAK;IAClC;IAEAM,QAAQ;QACN,MAAMC,QAAQ,IAAIV;QAClB,IAAI,OAAO,IAAI,CAACG,KAAK,KAAK,UAAU;YAClCO,MAAMP,KAAK,GAAG,IAAI,CAACA,KAAK;QAC1B,OAAO;YACL,mFAAmF;YACnFO,MAAMP,KAAK,GAAG,IAAI,CAACA,KAAK,CAACQ,KAAK,CAAC;QACjC;QACAD,MAAME,MAAM,GAAGC,IAAAA,oBAAS,EAAC,IAAI,CAACD,MAAM;QACpCF,MAAMI,IAAI,GAAGD,IAAAA,oBAAS,EAAC,IAAI,CAACC,IAAI;QAChCJ,MAAMK,IAAI,GAAG,IAAI,CAACA,IAAI;QACtB,OAAOL;IACT;IApDAM,YAAYb,KAA0B,CAAE;QAuBxCA,uBAAAA,SAAAA,KAAAA;QAEAS,uBAAAA,UAAAA,KAAAA;QAEAE,uBAAAA,QAAAA,KAAAA;QAEAC,uBAAAA,QAAAA,KAAAA;QA5BE,IAAIE;QACJ,IAAI,OAAOd,UAAU,YAAYA,iBAAiBe,YAAY;YAC5DD,UAAU;gBAAEd;YAAM;QACpB,OAAO;YACLc,UAAUd;QACZ;QAEA,IAAI,CAACA,KAAK,GAAGc,SAASd,SAAS;QAC/B,wDAAwD;QACxD,gEAAgE;QAChE,4DAA4D;QAC5D,EAAE;QACF,wEAAwE;QACxE,4EAA4E;QAC5E,8EAA8E;QAC9E,EAAE;QACF,iDAAiD;QACjD,IAAI,CAACS,MAAM,GAAGK,SAASL,UAAWP;QAClC,IAAI,CAACS,IAAI,GAAGG,SAASH,QAAQ,CAAC;QAC9B,IAAI,CAACC,IAAI,GAAGE,SAASF,QAAQ;IAC/B;AAgCF"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./VirtualFile"), exports);
|
|
6
|
-
function _export_star(from, to) {
|
|
7
|
-
Object.keys(from).forEach(function(k) {
|
|
8
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
-
Object.defineProperty(to, k, {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function() {
|
|
12
|
-
return from[k];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return from;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/virtual-file/index.browser.ts"],"sourcesContent":["export * from './VirtualFile';\n"],"names":[],"mappings":";;;;qBAAc"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./toVirtualFile"), exports);
|
|
6
|
-
_export_star(require("./VirtualFile"), exports);
|
|
7
|
-
function _export_star(from, to) {
|
|
8
|
-
Object.keys(from).forEach(function(k) {
|
|
9
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
-
Object.defineProperty(to, k, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function() {
|
|
13
|
-
return from[k];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return from;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/virtual-file/index.ts"],"sourcesContent":["export * from './toVirtualFile';\nexport * from './VirtualFile';\n"],"names":[],"mappings":";;;;qBAAc;qBACA"}
|