@solana/assertions 2.0.0-experimental.ff8c65b → 2.0.0-preview.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.
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ var errors = require('@solana/errors');
4
+
3
5
  // src/subtle-crypto.ts
4
6
  function assertIsSecureContext() {
5
7
  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
- );
8
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT);
9
9
  }
10
10
  }
11
11
  var cachedEd25519Decision;
@@ -33,36 +33,34 @@ async function isEd25519CurveSupported(subtle) {
33
33
  async function assertDigestCapabilityIsAvailable() {
34
34
  assertIsSecureContext();
35
35
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
36
- throw new Error("No digest implementation could be found");
36
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);
37
37
  }
38
38
  }
39
39
  async function assertKeyGenerationIsAvailable() {
40
40
  assertIsSecureContext();
41
41
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
42
- throw new Error("No key generation implementation could be found");
42
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);
43
43
  }
44
44
  if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
45
- throw new Error(
46
- "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"
47
- );
45
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);
48
46
  }
49
47
  }
50
48
  async function assertKeyExporterIsAvailable() {
51
49
  assertIsSecureContext();
52
50
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
53
- throw new Error("No key export implementation could be found");
51
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);
54
52
  }
55
53
  }
56
54
  async function assertSigningCapabilityIsAvailable() {
57
55
  assertIsSecureContext();
58
56
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
59
- throw new Error("No signing implementation could be found");
57
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);
60
58
  }
61
59
  }
62
60
  async function assertVerificationCapabilityIsAvailable() {
63
61
  assertIsSecureContext();
64
62
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
65
- throw new Error("No signature verification implementation could be found");
63
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);
66
64
  }
67
65
  }
68
66
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB;AAC7B,MAAmB,CAAC,WAAW,iBAAiB;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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC7D;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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n // TODO: Coded error.\n throw new Error('No digest implementation could be found');\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"]}
1
+ {"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,wBAAwB;AAC7B,MAAmB,CAAC,WAAW,iBAAiB;AAC5C,UAAM,IAAI,YAAY,2DAA2D;AAAA,EACrF;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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,iDAAiD;AAAA,EAC3E;AACJ;AAEA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AACzG,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAC5D,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACJ;AAEA,eAAsB,+BAA+B;AACjD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,cAAc,YAAY;AACvG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ;AAEA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAClG,UAAM,IAAI,YAAY,wDAAwD;AAAA,EAClF;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ","sourcesContent":["import {\n SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT,\n SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED,\n SolanaError,\n} from '@solana/errors';\n\nfunction assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT);\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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
+ import { SolanaError, SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT } from '@solana/errors';
2
+
1
3
  // src/subtle-crypto.ts
2
4
  function assertIsSecureContext() {
3
5
  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
- );
6
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT);
7
7
  }
8
8
  }
9
9
  var cachedEd25519Decision;
@@ -31,36 +31,34 @@ async function isEd25519CurveSupported(subtle) {
31
31
  async function assertDigestCapabilityIsAvailable() {
32
32
  assertIsSecureContext();
33
33
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
34
- throw new Error("No digest implementation could be found");
34
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);
35
35
  }
36
36
  }
37
37
  async function assertKeyGenerationIsAvailable() {
38
38
  assertIsSecureContext();
39
39
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
40
- throw new Error("No key generation implementation could be found");
40
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);
41
41
  }
42
42
  if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
43
- throw new Error(
44
- "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"
45
- );
43
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);
46
44
  }
47
45
  }
48
46
  async function assertKeyExporterIsAvailable() {
49
47
  assertIsSecureContext();
50
48
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
51
- throw new Error("No key export implementation could be found");
49
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);
52
50
  }
53
51
  }
54
52
  async function assertSigningCapabilityIsAvailable() {
55
53
  assertIsSecureContext();
56
54
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
57
- throw new Error("No signing implementation could be found");
55
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);
58
56
  }
59
57
  }
60
58
  async function assertVerificationCapabilityIsAvailable() {
61
59
  assertIsSecureContext();
62
60
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
63
- throw new Error("No signature verification implementation could be found");
61
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);
64
62
  }
65
63
  }
66
64
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB;AAC7B,MAAmB,CAAC,WAAW,iBAAiB;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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC7D;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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n // TODO: Coded error.\n throw new Error('No digest implementation could be found');\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"]}
1
+ {"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,wBAAwB;AAC7B,MAAmB,CAAC,WAAW,iBAAiB;AAC5C,UAAM,IAAI,YAAY,2DAA2D;AAAA,EACrF;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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,iDAAiD;AAAA,EAC3E;AACJ;AAEA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AACzG,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAC5D,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACJ;AAEA,eAAsB,+BAA+B;AACjD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,cAAc,YAAY;AACvG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ;AAEA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAClG,UAAM,IAAI,YAAY,wDAAwD;AAAA,EAClF;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ","sourcesContent":["import {\n SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT,\n SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED,\n SolanaError,\n} from '@solana/errors';\n\nfunction assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT);\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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);\n }\n}\n"]}
@@ -1,3 +1,5 @@
1
+ import { SolanaError, SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED } from '@solana/errors';
2
+
1
3
  // src/subtle-crypto.ts
2
4
  var cachedEd25519Decision;
3
5
  async function isEd25519CurveSupported(subtle) {
@@ -23,32 +25,30 @@ async function isEd25519CurveSupported(subtle) {
23
25
  }
24
26
  async function assertDigestCapabilityIsAvailable() {
25
27
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
26
- throw new Error("No digest implementation could be found");
28
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);
27
29
  }
28
30
  }
29
31
  async function assertKeyGenerationIsAvailable() {
30
32
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
31
- throw new Error("No key generation implementation could be found");
33
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);
32
34
  }
33
35
  if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
34
- throw new Error(
35
- "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"
36
- );
36
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);
37
37
  }
38
38
  }
39
39
  async function assertKeyExporterIsAvailable() {
40
40
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
41
- throw new Error("No key export implementation could be found");
41
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);
42
42
  }
43
43
  }
44
44
  async function assertSigningCapabilityIsAvailable() {
45
45
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
46
- throw new Error("No signing implementation could be found");
46
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);
47
47
  }
48
48
  }
49
49
  async function assertVerificationCapabilityIsAvailable() {
50
50
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
51
- throw new Error("No signature verification implementation could be found");
51
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);
52
52
  }
53
53
  }
54
54
 
@@ -1 +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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC7D;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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n // TODO: Coded error.\n throw new Error('No digest implementation could be found');\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"]}
1
+ {"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA;AAAA,EACI;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,wBAAwB;AAC7B,MAAI,OAA4C;AAC5C,UAAM,IAAI,YAAY,2DAA2D;AAAA,EACrF;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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,iDAAiD;AAAA,EAC3E;AACJ;AAEA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AACzG,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAC5D,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACJ;AAEA,eAAsB,+BAA+B;AACjD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,cAAc,YAAY;AACvG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ;AAEA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAClG,UAAM,IAAI,YAAY,wDAAwD;AAAA,EAClF;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ","sourcesContent":["import {\n SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT,\n SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED,\n SolanaError,\n} from '@solana/errors';\n\nfunction assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT);\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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);\n }\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var errors = require('@solana/errors');
4
+
3
5
  // src/subtle-crypto.ts
4
6
  var cachedEd25519Decision;
5
7
  async function isEd25519CurveSupported(subtle) {
@@ -25,32 +27,30 @@ async function isEd25519CurveSupported(subtle) {
25
27
  }
26
28
  async function assertDigestCapabilityIsAvailable() {
27
29
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
28
- throw new Error("No digest implementation could be found");
30
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);
29
31
  }
30
32
  }
31
33
  async function assertKeyGenerationIsAvailable() {
32
34
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
33
- throw new Error("No key generation implementation could be found");
35
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);
34
36
  }
35
37
  if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
36
- throw new Error(
37
- "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"
38
- );
38
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);
39
39
  }
40
40
  }
41
41
  async function assertKeyExporterIsAvailable() {
42
42
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
43
- throw new Error("No key export implementation could be found");
43
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);
44
44
  }
45
45
  }
46
46
  async function assertSigningCapabilityIsAvailable() {
47
47
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
48
- throw new Error("No signing implementation could be found");
48
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);
49
49
  }
50
50
  }
51
51
  async function assertVerificationCapabilityIsAvailable() {
52
52
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
53
- throw new Error("No signature verification implementation could be found");
53
+ throw new errors.SolanaError(errors.SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);
54
54
  }
55
55
  }
56
56
 
@@ -1 +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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC7D;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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n // TODO: Coded error.\n throw new Error('No digest implementation could be found');\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"]}
1
+ {"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA;AAAA,EACI;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,wBAAwB;AAC7B,MAAI,OAA4C;AAC5C,UAAM,IAAI,YAAY,2DAA2D;AAAA,EACrF;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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,iDAAiD;AAAA,EAC3E;AACJ;AAEA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AACzG,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAC5D,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACJ;AAEA,eAAsB,+BAA+B;AACjD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,cAAc,YAAY;AACvG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ;AAEA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAClG,UAAM,IAAI,YAAY,wDAAwD;AAAA,EAClF;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ","sourcesContent":["import {\n SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT,\n SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED,\n SolanaError,\n} from '@solana/errors';\n\nfunction assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT);\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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);\n }\n}\n"]}
@@ -1,3 +1,5 @@
1
+ import { SolanaError, SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED, SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED } from '@solana/errors';
2
+
1
3
  // src/subtle-crypto.ts
2
4
  var cachedEd25519Decision;
3
5
  async function isEd25519CurveSupported(subtle) {
@@ -23,32 +25,30 @@ async function isEd25519CurveSupported(subtle) {
23
25
  }
24
26
  async function assertDigestCapabilityIsAvailable() {
25
27
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
26
- throw new Error("No digest implementation could be found");
28
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);
27
29
  }
28
30
  }
29
31
  async function assertKeyGenerationIsAvailable() {
30
32
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
31
- throw new Error("No key generation implementation could be found");
33
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);
32
34
  }
33
35
  if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
34
- throw new Error(
35
- "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"
36
- );
36
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);
37
37
  }
38
38
  }
39
39
  async function assertKeyExporterIsAvailable() {
40
40
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
41
- throw new Error("No key export implementation could be found");
41
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);
42
42
  }
43
43
  }
44
44
  async function assertSigningCapabilityIsAvailable() {
45
45
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
46
- throw new Error("No signing implementation could be found");
46
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);
47
47
  }
48
48
  }
49
49
  async function assertVerificationCapabilityIsAvailable() {
50
50
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
51
- throw new Error("No signature verification implementation could be found");
51
+ throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);
52
52
  }
53
53
  }
54
54
 
@@ -1 +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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC7D;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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n // TODO: Coded error.\n throw new Error('No digest implementation could be found');\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"]}
1
+ {"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA;AAAA,EACI;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,wBAAwB;AAC7B,MAAI,OAA4C;AAC5C,UAAM,IAAI,YAAY,2DAA2D;AAAA,EACrF;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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,iDAAiD;AAAA,EAC3E;AACJ;AAEA,eAAsB,iCAAiC;AACnD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,gBAAgB,YAAY;AACzG,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACA,MAAI,CAAE,MAAM,wBAAwB,WAAW,OAAO,MAAM,GAAI;AAC5D,UAAM,IAAI,YAAY,4DAA4D;AAAA,EACtF;AACJ;AAEA,eAAsB,+BAA+B;AACjD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,cAAc,YAAY;AACvG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ;AAEA,eAAsB,qCAAqC;AACvD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,SAAS,YAAY;AAClG,UAAM,IAAI,YAAY,wDAAwD;AAAA,EAClF;AACJ;AAEA,eAAsB,0CAA0C;AAC5D,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AACpG,UAAM,IAAI,YAAY,0DAA0D;AAAA,EACpF;AACJ","sourcesContent":["import {\n SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT,\n SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED,\n SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED,\n SolanaError,\n} from '@solana/errors';\n\nfunction assertIsSecureContext() {\n if (__BROWSER__ && !globalThis.isSecureContext) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DISALLOWED_IN_INSECURE_CONTEXT);\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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__DIGEST_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyGenerationIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.generateKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__GENERATE_FUNCTION_UNIMPLEMENTED);\n }\n if (!(await isEd25519CurveSupported(globalThis.crypto.subtle))) {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__ED25519_ALGORITHM_UNIMPLEMENTED);\n }\n}\n\nexport async function assertKeyExporterIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.exportKey !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__EXPORT_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertSigningCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.sign !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__SIGN_FUNCTION_UNIMPLEMENTED);\n }\n}\n\nexport async function assertVerificationCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.verify !== 'function') {\n throw new SolanaError(SOLANA_ERROR__SUBTLE_CRYPTO__VERIFY_FUNCTION_UNIMPLEMENTED);\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- export * from './subtle-crypto';
1
+ export * from './subtle-crypto.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"subtle-crypto.d.ts","sourceRoot":"","sources":["../../src/subtle-crypto.ts"],"names":[],"mappings":"AA+BA,wBAAsB,iCAAiC,kBAMtD;AAED,wBAAsB,8BAA8B,kBAgBnD;AAED,wBAAsB,4BAA4B,kBAMjD;AAED,wBAAsB,kCAAkC,kBAMvD;AAED,wBAAsB,uCAAuC,kBAM5D"}
1
+ {"version":3,"file":"subtle-crypto.d.ts","sourceRoot":"","sources":["../../src/subtle-crypto.ts"],"names":[],"mappings":"AAsCA,wBAAsB,iCAAiC,kBAKtD;AAED,wBAAsB,8BAA8B,kBAQnD;AAED,wBAAsB,4BAA4B,kBAKjD;AAED,wBAAsB,kCAAkC,kBAKvD;AAED,wBAAsB,uCAAuC,kBAK5D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/assertions",
3
- "version": "2.0.0-experimental.ff8c65b",
3
+ "version": "2.0.0-preview.1",
4
4
  "description": "Helpers for asserting that a JavaScript environment supports certain features necessary for the operation of the Solana JavaScript SDK",
5
5
  "exports": {
6
6
  "browser": {
@@ -48,27 +48,8 @@
48
48
  "engine": {
49
49
  "node": ">=17.4"
50
50
  },
51
- "devDependencies": {
52
- "@solana/eslint-config-solana": "^1.0.2",
53
- "@swc/jest": "^0.2.29",
54
- "@types/jest": "^29.5.6",
55
- "@typescript-eslint/eslint-plugin": "^6.7.0",
56
- "@typescript-eslint/parser": "^6.3.0",
57
- "agadoo": "^3.0.0",
58
- "eslint": "^8.45.0",
59
- "eslint-plugin-jest": "^27.4.2",
60
- "eslint-plugin-sort-keys-fix": "^1.1.2",
61
- "jest": "^29.7.0",
62
- "jest-environment-jsdom": "^29.7.0",
63
- "jest-runner-eslint": "^2.1.2",
64
- "jest-runner-prettier": "^1.0.0",
65
- "prettier": "^2.8",
66
- "tsup": "7.2.0",
67
- "typescript": "^5.2.2",
68
- "version-from-git": "^1.1.1",
69
- "build-scripts": "0.0.0",
70
- "test-config": "0.0.0",
71
- "tsconfig": "0.0.0"
51
+ "dependencies": {
52
+ "@solana/errors": "2.0.0-preview.1"
72
53
  },
73
54
  "bundlewatch": {
74
55
  "defaultCompression": "gzip",
@@ -79,18 +60,19 @@
79
60
  ]
80
61
  },
81
62
  "scripts": {
82
- "compile:js": "tsup --config build-scripts/tsup.config.library.ts",
83
- "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
84
- "dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
85
- "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
63
+ "compile:js": "tsup --config build-scripts/tsup.config.package.ts",
64
+ "compile:typedefs": "tsc -p ./tsconfig.declarations.json && node ../../node_modules/@solana/build-scripts/add-js-extension-to-types.mjs",
65
+ "dev": "jest -c ../../node_modules/@solana/test-config/jest-dev.config.ts --rootDir . --watch",
66
+ "publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || pnpm publish --tag preview --access public --no-git-checks",
67
+ "publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
86
68
  "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
87
- "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
88
- "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
69
+ "test:lint": "jest -c ../../node_modules/@solana/test-config/jest-lint.config.ts --rootDir . --silent",
70
+ "test:prettier": "jest -c ../../node_modules/@solana/test-config/jest-prettier.config.ts --rootDir . --silent",
89
71
  "test:treeshakability:browser": "agadoo dist/index.browser.js",
90
72
  "test:treeshakability:native": "agadoo dist/index.native.js",
91
73
  "test:treeshakability:node": "agadoo dist/index.node.js",
92
74
  "test:typecheck": "tsc --noEmit",
93
- "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",
94
- "test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --rootDir . --silent"
75
+ "test:unit:browser": "jest -c ../../node_modules/@solana/test-config/jest-unit.config.browser.ts --rootDir . --silent",
76
+ "test:unit:node": "jest -c ../../node_modules/@solana/test-config/jest-unit.config.node.ts --rootDir . --silent"
95
77
  }
96
78
  }
@@ -1,81 +0,0 @@
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 assertDigestCapabilityIsAvailable() {
36
- assertIsSecureContext();
37
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
38
- throw new Error("No digest implementation could be found");
39
- }
40
- }
41
- async function assertKeyGenerationIsAvailable() {
42
- assertIsSecureContext();
43
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
44
- throw new Error("No key generation implementation could be found");
45
- }
46
- if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
47
- throw new Error(
48
- "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"
49
- );
50
- }
51
- }
52
- async function assertKeyExporterIsAvailable() {
53
- assertIsSecureContext();
54
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
55
- throw new Error("No key export implementation could be found");
56
- }
57
- }
58
- async function assertSigningCapabilityIsAvailable() {
59
- assertIsSecureContext();
60
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
61
- throw new Error("No signing implementation could be found");
62
- }
63
- }
64
- async function assertVerificationCapabilityIsAvailable() {
65
- assertIsSecureContext();
66
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
67
- throw new Error("No signature verification implementation could be found");
68
- }
69
- }
70
-
71
- exports.assertDigestCapabilityIsAvailable = assertDigestCapabilityIsAvailable;
72
- exports.assertKeyExporterIsAvailable = assertKeyExporterIsAvailable;
73
- exports.assertKeyGenerationIsAvailable = assertKeyGenerationIsAvailable;
74
- exports.assertSigningCapabilityIsAvailable = assertSigningCapabilityIsAvailable;
75
- exports.assertVerificationCapabilityIsAvailable = assertVerificationCapabilityIsAvailable;
76
-
77
- return exports;
78
-
79
- })({});
80
- //# sourceMappingURL=out.js.map
81
- //# sourceMappingURL=index.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/subtle-crypto.ts"],"names":[],"mappings":";AAAA,SAAS,wBAAwB;AAC7B,MAAmB,CAAC,WAAW,iBAAiB;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,oCAAoC;AACtD,wBAAsB;AACtB,MAAI,OAAO,WAAW,WAAW,eAAe,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY;AAEpG,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC7D;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 assertDigestCapabilityIsAvailable() {\n assertIsSecureContext();\n if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle?.digest !== 'function') {\n // TODO: Coded error.\n throw new Error('No digest implementation could be found');\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"]}
@@ -1,19 +0,0 @@
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 r(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?.digest!="function")throw new Error("No digest implementation could be found")}async function l(){if(o(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.generateKey!="function")throw new Error("No key generation implementation could be found");if(!await r(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 p(){if(o(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}async function c(){if(o(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}async function u(){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.assertDigestCapabilityIsAvailable = a;
12
- exports.assertKeyExporterIsAvailable = p;
13
- exports.assertKeyGenerationIsAvailable = l;
14
- exports.assertSigningCapabilityIsAvailable = c;
15
- exports.assertVerificationCapabilityIsAvailable = u;
16
-
17
- return exports;
18
-
19
- })({});