@solana/assertions 2.0.0-experimental.7d79aca
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/LICENSE +20 -0
- package/README.md +35 -0
- package/dist/index.browser.cjs +68 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +63 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.development.js +74 -0
- package/dist/index.development.js.map +1 -0
- package/dist/index.native.js +52 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +57 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +52 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.production.min.js +18 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/subtle-crypto.d.ts +5 -0
- package/dist/types/subtle-crypto.d.ts.map +1 -0
- package/package.json +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2018 Solana Labs, Inc
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[![npm][npm-image]][npm-url]
|
|
2
|
+
[![npm-downloads][npm-downloads-image]][npm-url]
|
|
3
|
+
[![semantic-release][semantic-release-image]][semantic-release-url]
|
|
4
|
+
<br />
|
|
5
|
+
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
|
|
6
|
+
|
|
7
|
+
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
8
|
+
[code-style-prettier-url]: https://github.com/prettier/prettier
|
|
9
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/assertions/experimental.svg?style=flat
|
|
10
|
+
[npm-image]: https://img.shields.io/npm/v/@solana/assertions/experimental.svg?style=flat
|
|
11
|
+
[npm-url]: https://www.npmjs.com/package/@solana/assertions/v/experimental
|
|
12
|
+
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
13
|
+
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
|
14
|
+
|
|
15
|
+
# @solana/assertions
|
|
16
|
+
|
|
17
|
+
This package contains utilities for asserting that a JavaScript environment supports certain features necessary for the operation of the Solana JavaScript SDK.
|
|
18
|
+
|
|
19
|
+
## Functions
|
|
20
|
+
|
|
21
|
+
`assertKeyExporterIsAvailable()`
|
|
22
|
+
|
|
23
|
+
Throws an exception unless `crypto.subtle.exportKey()` is available in the current JavaScript environment.
|
|
24
|
+
|
|
25
|
+
`assertKeyGenerationIsAvailable()`
|
|
26
|
+
|
|
27
|
+
Throws an exception unless `crypto.subtle.generateKey()` is available in the current JavaScript environment and has support for the `Ed25519` curve.
|
|
28
|
+
|
|
29
|
+
`assertSigningCapabilityIsAvailable()`
|
|
30
|
+
|
|
31
|
+
Throws an exception unless `crypto.subtle.sign()` is available in the current JavaScript environment.
|
|
32
|
+
|
|
33
|
+
`assertVerificationCapabilityIsAvailable()`
|
|
34
|
+
|
|
35
|
+
Throws an exception unless `crypto.subtle.sign()` is available in the current JavaScript environment.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/subtle-crypto.ts
|
|
4
|
+
function assertIsSecureContext() {
|
|
5
|
+
if (!globalThis.isSecureContext) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
var cachedEd25519Decision;
|
|
12
|
+
async function isEd25519CurveSupported(subtle) {
|
|
13
|
+
if (cachedEd25519Decision === void 0) {
|
|
14
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
15
|
+
subtle.generateKey(
|
|
16
|
+
"Ed25519",
|
|
17
|
+
/* extractable */
|
|
18
|
+
false,
|
|
19
|
+
["sign", "verify"]
|
|
20
|
+
).catch(() => {
|
|
21
|
+
resolve(cachedEd25519Decision = false);
|
|
22
|
+
}).then(() => {
|
|
23
|
+
resolve(cachedEd25519Decision = true);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
28
|
+
return cachedEd25519Decision;
|
|
29
|
+
} else {
|
|
30
|
+
return await cachedEd25519Decision;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function assertKeyGenerationIsAvailable() {
|
|
34
|
+
assertIsSecureContext();
|
|
35
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
36
|
+
throw new Error("No key generation implementation could be found");
|
|
37
|
+
}
|
|
38
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function assertKeyExporterIsAvailable() {
|
|
45
|
+
assertIsSecureContext();
|
|
46
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
47
|
+
throw new Error("No key export implementation could be found");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
51
|
+
assertIsSecureContext();
|
|
52
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
53
|
+
throw new Error("No signing implementation could be found");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
57
|
+
assertIsSecureContext();
|
|
58
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
59
|
+
throw new Error("No signature verification implementation could be found");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.assertKeyExporterIsAvailable = assertKeyExporterIsAvailable;
|
|
64
|
+
exports.assertKeyGenerationIsAvailable = assertKeyGenerationIsAvailable;
|
|
65
|
+
exports.assertSigningCapabilityIsAvailable = assertSigningCapabilityIsAvailable;
|
|
66
|
+
exports.assertVerificationCapabilityIsAvailable = assertVerificationCapabilityIsAvailable;
|
|
67
|
+
//# sourceMappingURL=out.js.map
|
|
68
|
+
//# sourceMappingURL=index.browser.cjs.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J;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC7E;AACJ","sourcesContent":["function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error(\n 'This runtime does not support the generation of Ed25519 key pairs.\\n\\nInstall and ' +\n 'import `@solana/webcrypto-ed25519-polyfill` before generating keys in ' +\n 'environments that do not support Ed25519.\\n\\nFor a list of runtimes that ' +\n 'currently support Ed25519 operations, visit ' +\n 'https://github.com/WICG/webcrypto-secure-curves/issues/20'\n );\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/subtle-crypto.ts
|
|
2
|
+
function assertIsSecureContext() {
|
|
3
|
+
if (!globalThis.isSecureContext) {
|
|
4
|
+
throw new Error(
|
|
5
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
var cachedEd25519Decision;
|
|
10
|
+
async function isEd25519CurveSupported(subtle) {
|
|
11
|
+
if (cachedEd25519Decision === void 0) {
|
|
12
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
13
|
+
subtle.generateKey(
|
|
14
|
+
"Ed25519",
|
|
15
|
+
/* extractable */
|
|
16
|
+
false,
|
|
17
|
+
["sign", "verify"]
|
|
18
|
+
).catch(() => {
|
|
19
|
+
resolve(cachedEd25519Decision = false);
|
|
20
|
+
}).then(() => {
|
|
21
|
+
resolve(cachedEd25519Decision = true);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
26
|
+
return cachedEd25519Decision;
|
|
27
|
+
} else {
|
|
28
|
+
return await cachedEd25519Decision;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function assertKeyGenerationIsAvailable() {
|
|
32
|
+
assertIsSecureContext();
|
|
33
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
34
|
+
throw new Error("No key generation implementation could be found");
|
|
35
|
+
}
|
|
36
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function assertKeyExporterIsAvailable() {
|
|
43
|
+
assertIsSecureContext();
|
|
44
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
45
|
+
throw new Error("No key export implementation could be found");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
49
|
+
assertIsSecureContext();
|
|
50
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
51
|
+
throw new Error("No signing implementation could be found");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
55
|
+
assertIsSecureContext();
|
|
56
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
57
|
+
throw new Error("No signature verification implementation could be found");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { assertKeyExporterIsAvailable, assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable };
|
|
62
|
+
//# sourceMappingURL=out.js.map
|
|
63
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB;AAC7B,MAA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AAEpG,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC7E;AACJ","sourcesContent":["function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error(\n 'This runtime does not support the generation of Ed25519 key pairs.\\n\\nInstall and ' +\n 'import `@solana/webcrypto-ed25519-polyfill` before generating keys in ' +\n 'environments that do not support Ed25519.\\n\\nFor a list of runtimes that ' +\n 'currently support Ed25519 operations, visit ' +\n 'https://github.com/WICG/webcrypto-secure-curves/issues/20'\n );\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
this.globalThis = this.globalThis || {};
|
|
2
|
+
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
// src/subtle-crypto.ts
|
|
6
|
+
function assertIsSecureContext() {
|
|
7
|
+
if (!globalThis.isSecureContext) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
var cachedEd25519Decision;
|
|
14
|
+
async function isEd25519CurveSupported(subtle) {
|
|
15
|
+
if (cachedEd25519Decision === void 0) {
|
|
16
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
17
|
+
subtle.generateKey(
|
|
18
|
+
"Ed25519",
|
|
19
|
+
/* extractable */
|
|
20
|
+
false,
|
|
21
|
+
["sign", "verify"]
|
|
22
|
+
).catch(() => {
|
|
23
|
+
resolve(cachedEd25519Decision = false);
|
|
24
|
+
}).then(() => {
|
|
25
|
+
resolve(cachedEd25519Decision = true);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
30
|
+
return cachedEd25519Decision;
|
|
31
|
+
} else {
|
|
32
|
+
return await cachedEd25519Decision;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function assertKeyGenerationIsAvailable() {
|
|
36
|
+
assertIsSecureContext();
|
|
37
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
38
|
+
throw new Error("No key generation implementation could be found");
|
|
39
|
+
}
|
|
40
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function assertKeyExporterIsAvailable() {
|
|
47
|
+
assertIsSecureContext();
|
|
48
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
49
|
+
throw new Error("No key export implementation could be found");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
53
|
+
assertIsSecureContext();
|
|
54
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
55
|
+
throw new Error("No signing implementation could be found");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
59
|
+
assertIsSecureContext();
|
|
60
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
61
|
+
throw new Error("No signature verification implementation could be found");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.assertKeyExporterIsAvailable = assertKeyExporterIsAvailable;
|
|
66
|
+
exports.assertKeyGenerationIsAvailable = assertKeyGenerationIsAvailable;
|
|
67
|
+
exports.assertSigningCapabilityIsAvailable = assertSigningCapabilityIsAvailable;
|
|
68
|
+
exports.assertVerificationCapabilityIsAvailable = assertVerificationCapabilityIsAvailable;
|
|
69
|
+
|
|
70
|
+
return exports;
|
|
71
|
+
|
|
72
|
+
})({});
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AQ,SAAS,YAAY;AAElG,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC9D;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC7E;AACJ","sourcesContent":["function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error(\n 'This runtime does not support the generation of Ed25519 key pairs.\\n\\nInstall and ' +\n 'import `@solana/webcrypto-ed25519-polyfill` before generating keys in ' +\n 'environments that do not support Ed25519.\\n\\nFor a list of runtimes that ' +\n 'currently support Ed25519 operations, visit ' +\n 'https://github.com/WICG/webcrypto-secure-curves/issues/20'\n );\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/subtle-crypto.ts
|
|
2
|
+
var cachedEd25519Decision;
|
|
3
|
+
async function isEd25519CurveSupported(subtle) {
|
|
4
|
+
if (cachedEd25519Decision === void 0) {
|
|
5
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
6
|
+
subtle.generateKey(
|
|
7
|
+
"Ed25519",
|
|
8
|
+
/* extractable */
|
|
9
|
+
false,
|
|
10
|
+
["sign", "verify"]
|
|
11
|
+
).catch(() => {
|
|
12
|
+
resolve(cachedEd25519Decision = false);
|
|
13
|
+
}).then(() => {
|
|
14
|
+
resolve(cachedEd25519Decision = true);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
19
|
+
return cachedEd25519Decision;
|
|
20
|
+
} else {
|
|
21
|
+
return await cachedEd25519Decision;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function assertKeyGenerationIsAvailable() {
|
|
25
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
26
|
+
throw new Error("No key generation implementation could be found");
|
|
27
|
+
}
|
|
28
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function assertKeyExporterIsAvailable() {
|
|
35
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
36
|
+
throw new Error("No key export implementation could be found");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
40
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
41
|
+
throw new Error("No signing implementation could be found");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
45
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
46
|
+
throw new Error("No signature verification implementation could be found");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { assertKeyExporterIsAvailable, assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable };
|
|
51
|
+
//# sourceMappingURL=out.js.map
|
|
52
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB;AAC7B,MAAI,OAA4C;AAE5C,UAAM,IAAI;AAAA,MACN;AAAA,IAEJ;AAAA,EACJ;AACJ;AAEA,IAAI;AACJ,eAAe,wBAAwB,QAAwC;AAC3E,MAAI,0BAA0B,QAAW;AACrC,4BAAwB,IAAI,QAAQ,aAAW;AAC3C,aACK;AAAA,QAAY;AAAA;AAAA,QAA6B;AAAA,QAAO,CAAC,QAAQ,QAAQ;AAAA,MAAC,EAClE,MAAM,MAAM;AACT,gBAAS,wBAAwB,KAAM;AAAA,MAC3C,CAAC,EACA,KAAK,MAAM;AACR,gBAAS,wBAAwB,IAAK;AAAA,MAC1C,CAAC;AAAA,IACT,CAAC;AAAA,EACL;AACA,MAAI,OAAO,0BAA0B,WAAW;AAC5C,WAAO;AAAA,EACX,OAAO;AACH,WAAO,MAAM;AAAA,EACjB;AACJ;AAEA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AAEzG,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACrE;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAE5D,UAAM,IAAI;AAAA,MACN;AAAA,IAKJ;AAAA,EACJ;AACJ;AAEA,eAAsB,+BAA+B;AACjD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,cAAc,YAAY;AAEvG,UAAM,IAAI,MAAM,6CAA6C;AAAA,EACjE;AACJ;AAEA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAElG,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC9D;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC7E;AACJ","sourcesContent":["function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error(\n 'This runtime does not support the generation of Ed25519 key pairs.\\n\\nInstall and ' +\n 'import `@solana/webcrypto-ed25519-polyfill` before generating keys in ' +\n 'environments that do not support Ed25519.\\n\\nFor a list of runtimes that ' +\n 'currently support Ed25519 operations, visit ' +\n 'https://github.com/WICG/webcrypto-secure-curves/issues/20'\n );\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/subtle-crypto.ts
|
|
4
|
+
var cachedEd25519Decision;
|
|
5
|
+
async function isEd25519CurveSupported(subtle) {
|
|
6
|
+
if (cachedEd25519Decision === void 0) {
|
|
7
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
8
|
+
subtle.generateKey(
|
|
9
|
+
"Ed25519",
|
|
10
|
+
/* extractable */
|
|
11
|
+
false,
|
|
12
|
+
["sign", "verify"]
|
|
13
|
+
).catch(() => {
|
|
14
|
+
resolve(cachedEd25519Decision = false);
|
|
15
|
+
}).then(() => {
|
|
16
|
+
resolve(cachedEd25519Decision = true);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
21
|
+
return cachedEd25519Decision;
|
|
22
|
+
} else {
|
|
23
|
+
return await cachedEd25519Decision;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function assertKeyGenerationIsAvailable() {
|
|
27
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
28
|
+
throw new Error("No key generation implementation could be found");
|
|
29
|
+
}
|
|
30
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function assertKeyExporterIsAvailable() {
|
|
37
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
38
|
+
throw new Error("No key export implementation could be found");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
42
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
43
|
+
throw new Error("No signing implementation could be found");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
47
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
48
|
+
throw new Error("No signature verification implementation could be found");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.assertKeyExporterIsAvailable = assertKeyExporterIsAvailable;
|
|
53
|
+
exports.assertKeyGenerationIsAvailable = assertKeyGenerationIsAvailable;
|
|
54
|
+
exports.assertSigningCapabilityIsAvailable = assertSigningCapabilityIsAvailable;
|
|
55
|
+
exports.assertVerificationCapabilityIsAvailable = assertVerificationCapabilityIsAvailable;
|
|
56
|
+
//# sourceMappingURL=out.js.map
|
|
57
|
+
//# sourceMappingURL=index.node.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB;AAC7B,MAAI,OAA4C;AAE5C,UAAM,IAAI;AAAA,MACN;AAAA,IAEJ;AAAA,EACJ;AACJ;AAEA,IAAI;AACJ,eAAe,wBAAwB,QAAwC;AAC3E,MAAI,0BAA0B,QAAW;AACrC,4BAAwB,IAAI,QAAQ,aAAW;AAC3C,aACK;AAAA,QAAY;AAAA;AAAA,QAA6B;AAAA,QAAO,CAAC,QAAQ,QAAQ;AAAA,MAAC,EAClE,MAAM,MAAM;AACT,gBAAS,wBAAwB,KAAM;AAAA,MAC3C,CAAC,EACA,KAAK,MAAM;AACR,gBAAS,wBAAwB,IAAK;AAAA,MAC1C,CAAC;AAAA,IACT,CAAC;AAAA,EACL;AACA,MAAI,OAAO,0BAA0B,WAAW;AAC5C,WAAO;AAAA,EACX,OAAO;AACH,WAAO,MAAM;AAAA,EACjB;AACJ;AAEA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AAEzG,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACrE;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAE5D,UAAM,IAAI;AAAA,MACN;AAAA,IAKJ;AAAA,EACJ;AACJ;AAEA,eAAsB,+BAA+B;AACjD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,cAAc,YAAY;AAEvG,UAAM,IAAI,MAAM,6CAA6C;AAAA,EACjE;AACJ;AAEA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAElG,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC9D;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC7E;AACJ","sourcesContent":["function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error(\n 'This runtime does not support the generation of Ed25519 key pairs.\\n\\nInstall and ' +\n 'import `@solana/webcrypto-ed25519-polyfill` before generating keys in ' +\n 'environments that do not support Ed25519.\\n\\nFor a list of runtimes that ' +\n 'currently support Ed25519 operations, visit ' +\n 'https://github.com/WICG/webcrypto-secure-curves/issues/20'\n );\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// src/subtle-crypto.ts
|
|
2
|
+
var cachedEd25519Decision;
|
|
3
|
+
async function isEd25519CurveSupported(subtle) {
|
|
4
|
+
if (cachedEd25519Decision === void 0) {
|
|
5
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
6
|
+
subtle.generateKey(
|
|
7
|
+
"Ed25519",
|
|
8
|
+
/* extractable */
|
|
9
|
+
false,
|
|
10
|
+
["sign", "verify"]
|
|
11
|
+
).catch(() => {
|
|
12
|
+
resolve(cachedEd25519Decision = false);
|
|
13
|
+
}).then(() => {
|
|
14
|
+
resolve(cachedEd25519Decision = true);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
19
|
+
return cachedEd25519Decision;
|
|
20
|
+
} else {
|
|
21
|
+
return await cachedEd25519Decision;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function assertKeyGenerationIsAvailable() {
|
|
25
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
26
|
+
throw new Error("No key generation implementation could be found");
|
|
27
|
+
}
|
|
28
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function assertKeyExporterIsAvailable() {
|
|
35
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
36
|
+
throw new Error("No key export implementation could be found");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
40
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
41
|
+
throw new Error("No signing implementation could be found");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
45
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
46
|
+
throw new Error("No signature verification implementation could be found");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { assertKeyExporterIsAvailable, assertKeyGenerationIsAvailable, assertSigningCapabilityIsAvailable, assertVerificationCapabilityIsAvailable };
|
|
51
|
+
//# sourceMappingURL=out.js.map
|
|
52
|
+
//# sourceMappingURL=index.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB;AAC7B,MAAI,OAA4C;AAE5C,UAAM,IAAI;AAAA,MACN;AAAA,IAEJ;AAAA,EACJ;AACJ;AAEA,IAAI;AACJ,eAAe,wBAAwB,QAAwC;AAC3E,MAAI,0BAA0B,QAAW;AACrC,4BAAwB,IAAI,QAAQ,aAAW;AAC3C,aACK;AAAA,QAAY;AAAA;AAAA,QAA6B;AAAA,QAAO,CAAC,QAAQ,QAAQ;AAAA,MAAC,EAClE,MAAM,MAAM;AACT,gBAAS,wBAAwB,KAAM;AAAA,MAC3C,CAAC,EACA,KAAK,MAAM;AACR,gBAAS,wBAAwB,IAAK;AAAA,MAC1C,CAAC;AAAA,IACT,CAAC;AAAA,EACL;AACA,MAAI,OAAO,0BAA0B,WAAW;AAC5C,WAAO;AAAA,EACX,OAAO;AACH,WAAO,MAAM;AAAA,EACjB;AACJ;AAEA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AAEzG,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACrE;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAE5D,UAAM,IAAI;AAAA,MACN;AAAA,IAKJ;AAAA,EACJ;AACJ;AAEA,eAAsB,+BAA+B;AACjD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,cAAc,YAAY;AAEvG,UAAM,IAAI,MAAM,6CAA6C;AAAA,EACjE;AACJ;AAEA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAElG,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC9D;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC7E;AACJ","sourcesContent":["function assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n // TODO: Coded error.\n throw new Error(\n 'Cryptographic operations are only allowed in secure browser contexts. Read more ' +\n 'here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts'\n );\n }\n}\n\nlet cachedEd25519Decision: PromiseLike<boolean> | boolean | undefined;\nasync function isEd25519CurveSupported(subtle: SubtleCrypto): Promise<boolean> {\n if (cachedEd25519Decision === undefined) {\n cachedEd25519Decision = new Promise(resolve => {\n subtle\n .generateKey('Ed25519', /* extractable */ false, ['sign', 'verify'])\n .catch(() => {\n resolve((cachedEd25519Decision = false));\n })\n .then(() => {\n resolve((cachedEd25519Decision = true));\n });\n });\n }\n if (typeof cachedEd25519Decision === 'boolean') {\n return cachedEd25519Decision;\n } else {\n return await cachedEd25519Decision;\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key generation implementation could be found');\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n // TODO: Coded error.\n throw new Error(\n 'This runtime does not support the generation of Ed25519 key pairs.\\n\\nInstall and ' +\n 'import `@solana/webcrypto-ed25519-polyfill` before generating keys in ' +\n 'environments that do not support Ed25519.\\n\\nFor a list of runtimes that ' +\n 'currently support Ed25519 operations, visit ' +\n 'https://github.com/WICG/webcrypto-secure-curves/issues/20'\n );\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n // TODO: Coded error.\n throw new Error('No key export implementation could be found');\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n // TODO: Coded error.\n throw new Error('No signing implementation could be found');\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n // TODO: Coded error.\n throw new Error('No signature verification implementation could be found');\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
this.globalThis = this.globalThis || {};
|
|
2
|
+
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
function o(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}var e;async function i(n){return e===void 0&&(e=new Promise(t=>{n.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{t(e=!1);}).then(()=>{t(e=!0);});})),typeof e=="boolean"?e:await e}async function a(){if(o(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.generateKey!="function")throw new Error("No key generation implementation could be found");if(!await i(globalThis.crypto.subtle))throw new Error(`This runtime does not support the generation of Ed25519 key pairs.
|
|
6
|
+
|
|
7
|
+
Install and import \`@solana/webcrypto-ed25519-polyfill\` before generating keys in environments that do not support Ed25519.
|
|
8
|
+
|
|
9
|
+
For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20`)}async function l(){if(o(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}async function p(){if(o(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}async function c(){if(o(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.verify!="function")throw new Error("No signature verification implementation could be found")}
|
|
10
|
+
|
|
11
|
+
exports.assertKeyExporterIsAvailable = l;
|
|
12
|
+
exports.assertKeyGenerationIsAvailable = a;
|
|
13
|
+
exports.assertSigningCapabilityIsAvailable = p;
|
|
14
|
+
exports.assertVerificationCapabilityIsAvailable = c;
|
|
15
|
+
|
|
16
|
+
return exports;
|
|
17
|
+
|
|
18
|
+
})({});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function assertKeyGenerationIsAvailable(): Promise<void>;
|
|
2
|
+
export declare function assertKeyExporterIsAvailable(): Promise<void>;
|
|
3
|
+
export declare function assertSigningCapabilityIsAvailable(): Promise<void>;
|
|
4
|
+
export declare function assertVerificationCapabilityIsAvailable(): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=subtle-crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtle-crypto.d.ts","sourceRoot":"","sources":["../../src/subtle-crypto.ts"],"names":[],"mappings":"AA+BA,wBAAsB,8BAA8B,kBAgBnD;AAED,wBAAsB,4BAA4B,kBAMjD;AAED,wBAAsB,kCAAkC,kBAMvD;AAED,wBAAsB,uCAAuC,kBAM5D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solana/assertions",
|
|
3
|
+
"version": "2.0.0-experimental.7d79aca",
|
|
4
|
+
"description": "Helpers for asserting that a JavaScript environment supports certain features necessary for the operation of the Solana JavaScript SDK",
|
|
5
|
+
"exports": {
|
|
6
|
+
"browser": {
|
|
7
|
+
"import": "./dist/index.browser.js",
|
|
8
|
+
"require": "./dist/index.browser.cjs"
|
|
9
|
+
},
|
|
10
|
+
"node": {
|
|
11
|
+
"import": "./dist/index.node.js",
|
|
12
|
+
"require": "./dist/index.node.cjs"
|
|
13
|
+
},
|
|
14
|
+
"react-native": "./dist/index.native.js",
|
|
15
|
+
"types": "./dist/types/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"browser": {
|
|
18
|
+
"./dist/index.node.cjs": "./dist/index.browser.cjs",
|
|
19
|
+
"./dist/index.node.js": "./dist/index.browser.js"
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.node.cjs",
|
|
22
|
+
"module": "./dist/index.node.js",
|
|
23
|
+
"react-native": "./dist/index.native.js",
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"files": [
|
|
27
|
+
"./dist/"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"keywords": [
|
|
31
|
+
"blockchain",
|
|
32
|
+
"solana",
|
|
33
|
+
"web3"
|
|
34
|
+
],
|
|
35
|
+
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/solana-labs/solana-web3.js"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "http://github.com/solana-labs/solana-web3.js/issues"
|
|
43
|
+
},
|
|
44
|
+
"browserslist": [
|
|
45
|
+
"supports bigint and not dead",
|
|
46
|
+
"maintained node versions"
|
|
47
|
+
],
|
|
48
|
+
"engine": {
|
|
49
|
+
"node": ">=17.4"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@solana/eslint-config-solana": "^1.0.2",
|
|
53
|
+
"@swc/core": "^1.3.71",
|
|
54
|
+
"@swc/jest": "^0.2.26",
|
|
55
|
+
"@types/jest": "^29.5.3",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
57
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
58
|
+
"agadoo": "^3.0.0",
|
|
59
|
+
"eslint": "^8.45.0",
|
|
60
|
+
"eslint-plugin-jest": "^27.2.3",
|
|
61
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
62
|
+
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
63
|
+
"jest": "^29.6.1",
|
|
64
|
+
"jest-environment-jsdom": "^29.6.0",
|
|
65
|
+
"jest-runner-eslint": "^2.1.0",
|
|
66
|
+
"jest-runner-prettier": "^1.0.0",
|
|
67
|
+
"postcss": "^8.4.12",
|
|
68
|
+
"prettier": "^2.8.8",
|
|
69
|
+
"ts-node": "^10.9.1",
|
|
70
|
+
"tsup": "6.7.0",
|
|
71
|
+
"typescript": "^5.1.6",
|
|
72
|
+
"version-from-git": "^1.1.1",
|
|
73
|
+
"build-scripts": "0.0.0",
|
|
74
|
+
"test-config": "0.0.0",
|
|
75
|
+
"tsconfig": "0.0.0"
|
|
76
|
+
},
|
|
77
|
+
"bundlewatch": {
|
|
78
|
+
"defaultCompression": "gzip",
|
|
79
|
+
"files": [
|
|
80
|
+
{
|
|
81
|
+
"path": "./dist/index*.js"
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"scripts": {
|
|
86
|
+
"compile:js": "tsup --config build-scripts/tsup.config.library.ts",
|
|
87
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
88
|
+
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
89
|
+
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
|
|
90
|
+
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
91
|
+
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
92
|
+
"test:treeshakability:browser": "agadoo dist/index.browser.js",
|
|
93
|
+
"test:treeshakability:native": "agadoo dist/index.node.js",
|
|
94
|
+
"test:treeshakability:node": "agadoo dist/index.native.js",
|
|
95
|
+
"test:typecheck": "tsc --noEmit",
|
|
96
|
+
"test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
97
|
+
"test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
98
|
+
}
|
|
99
|
+
}
|