@metamask/utils 6.2.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/cjs/assert.js +116 -0
  3. package/dist/cjs/assert.js.map +1 -0
  4. package/dist/cjs/base64.js +32 -0
  5. package/dist/cjs/base64.js.map +1 -0
  6. package/dist/cjs/bytes.js +255 -0
  7. package/dist/cjs/bytes.js.map +1 -0
  8. package/dist/cjs/caip-types.js +115 -0
  9. package/dist/cjs/caip-types.js.map +1 -0
  10. package/dist/cjs/checksum.js +17 -0
  11. package/dist/cjs/checksum.js.map +1 -0
  12. package/dist/cjs/coercers.js +96 -0
  13. package/dist/cjs/coercers.js.map +1 -0
  14. package/dist/cjs/collections.js +157 -0
  15. package/dist/cjs/collections.js.map +1 -0
  16. package/dist/cjs/encryption-types.js +6 -0
  17. package/dist/cjs/encryption-types.js.map +1 -0
  18. package/dist/cjs/hex.js +107 -0
  19. package/dist/cjs/hex.js.map +1 -0
  20. package/dist/cjs/index.js +37 -0
  21. package/dist/cjs/index.js.map +1 -0
  22. package/dist/cjs/json.js +263 -0
  23. package/dist/cjs/json.js.map +1 -0
  24. package/dist/cjs/keyring.js +6 -0
  25. package/dist/cjs/keyring.js.map +1 -0
  26. package/dist/cjs/logging.js +33 -0
  27. package/dist/cjs/logging.js.map +1 -0
  28. package/dist/cjs/misc.js +111 -0
  29. package/dist/cjs/misc.js.map +1 -0
  30. package/dist/cjs/number.js +52 -0
  31. package/dist/cjs/number.js.map +1 -0
  32. package/dist/cjs/opaque.js +8 -0
  33. package/dist/cjs/opaque.js.map +1 -0
  34. package/dist/cjs/time.js +63 -0
  35. package/dist/cjs/time.js.map +1 -0
  36. package/dist/cjs/transaction-types.js +6 -0
  37. package/dist/cjs/transaction-types.js.map +1 -0
  38. package/dist/cjs/versions.js +79 -0
  39. package/dist/cjs/versions.js.map +1 -0
  40. package/dist/{assert.js → esm/assert.js} +30 -35
  41. package/dist/esm/assert.js.map +1 -0
  42. package/dist/{base64.js → esm/base64.js} +10 -16
  43. package/dist/esm/base64.js.map +1 -0
  44. package/dist/{bytes.js → esm/bytes.js} +50 -93
  45. package/dist/esm/bytes.js.map +1 -0
  46. package/dist/esm/caip-types.js +99 -0
  47. package/dist/esm/caip-types.js.map +1 -0
  48. package/dist/esm/checksum.js +7 -0
  49. package/dist/esm/checksum.js.map +1 -0
  50. package/dist/{coercers.js → esm/coercers.js} +43 -52
  51. package/dist/esm/coercers.js.map +1 -0
  52. package/dist/esm/collections.js +140 -0
  53. package/dist/esm/collections.js.map +1 -0
  54. package/dist/esm/encryption-types.js +3 -0
  55. package/dist/esm/encryption-types.js.map +1 -0
  56. package/dist/esm/hex.js +108 -0
  57. package/dist/esm/hex.js.map +1 -0
  58. package/dist/{index.d.ts → esm/index.js} +3 -0
  59. package/dist/esm/index.js.map +1 -0
  60. package/dist/esm/json.js +301 -0
  61. package/dist/esm/json.js.map +1 -0
  62. package/dist/esm/keyring.js +3 -0
  63. package/dist/esm/keyring.js.map +1 -0
  64. package/dist/{logging.js → esm/logging.js} +5 -14
  65. package/dist/esm/logging.js.map +1 -0
  66. package/dist/{misc.js → esm/misc.js} +37 -42
  67. package/dist/esm/misc.js.map +1 -0
  68. package/dist/{number.js → esm/number.js} +18 -28
  69. package/dist/esm/number.js.map +1 -0
  70. package/dist/esm/opaque.js +5 -0
  71. package/dist/esm/opaque.js.map +1 -0
  72. package/dist/esm/package.json +1 -0
  73. package/dist/esm/time.js +53 -0
  74. package/dist/esm/time.js.map +1 -0
  75. package/dist/esm/transaction-types.js +3 -0
  76. package/dist/esm/transaction-types.js.map +1 -0
  77. package/dist/esm/versions.js +78 -0
  78. package/dist/esm/versions.js.map +1 -0
  79. package/dist/{assert.d.ts → types/assert.d.ts} +3 -2
  80. package/dist/types/assert.d.ts.map +1 -0
  81. package/dist/{base64.d.ts → types/base64.d.ts} +3 -2
  82. package/dist/types/base64.d.ts.map +1 -0
  83. package/dist/{bytes.d.ts → types/bytes.d.ts} +2 -1
  84. package/dist/types/bytes.d.ts.map +1 -0
  85. package/dist/types/caip-types.d.ts +93 -0
  86. package/dist/types/caip-types.d.ts.map +1 -0
  87. package/dist/types/caip-types.test-d.d.ts +2 -0
  88. package/dist/types/caip-types.test-d.d.ts.map +1 -0
  89. package/dist/{checksum.d.ts → types/checksum.d.ts} +1 -0
  90. package/dist/types/checksum.d.ts.map +1 -0
  91. package/dist/{coercers.d.ts → types/coercers.d.ts} +3 -2
  92. package/dist/types/coercers.d.ts.map +1 -0
  93. package/dist/{collections.d.ts → types/collections.d.ts} +1 -0
  94. package/dist/types/collections.d.ts.map +1 -0
  95. package/dist/{encryption-types.d.ts → types/encryption-types.d.ts} +1 -0
  96. package/dist/types/encryption-types.d.ts.map +1 -0
  97. package/dist/{hex.d.ts → types/hex.d.ts} +2 -1
  98. package/dist/types/hex.d.ts.map +1 -0
  99. package/dist/types/hex.test-d.d.ts +2 -0
  100. package/dist/types/hex.test-d.d.ts.map +1 -0
  101. package/dist/types/index.d.ts +19 -0
  102. package/dist/types/index.d.ts.map +1 -0
  103. package/dist/{json.d.ts → types/json.d.ts} +3 -2
  104. package/dist/types/json.d.ts.map +1 -0
  105. package/dist/types/json.test-d.d.ts +2 -0
  106. package/dist/types/json.test-d.d.ts.map +1 -0
  107. package/dist/{keyring.d.ts → types/keyring.d.ts} +3 -2
  108. package/dist/types/keyring.d.ts.map +1 -0
  109. package/dist/{logging.d.ts → types/logging.d.ts} +2 -1
  110. package/dist/types/logging.d.ts.map +1 -0
  111. package/dist/{misc.d.ts → types/misc.d.ts} +13 -0
  112. package/dist/types/misc.d.ts.map +1 -0
  113. package/dist/types/misc.test-d.d.ts +2 -0
  114. package/dist/types/misc.test-d.d.ts.map +1 -0
  115. package/dist/{number.d.ts → types/number.d.ts} +1 -0
  116. package/dist/types/number.d.ts.map +1 -0
  117. package/dist/{opaque.d.ts → types/opaque.d.ts} +1 -0
  118. package/dist/types/opaque.d.ts.map +1 -0
  119. package/dist/{time.d.ts → types/time.d.ts} +1 -0
  120. package/dist/types/time.d.ts.map +1 -0
  121. package/dist/{transaction-types.d.ts → types/transaction-types.d.ts} +3 -2
  122. package/dist/types/transaction-types.d.ts.map +1 -0
  123. package/dist/{versions.d.ts → types/versions.d.ts} +3 -2
  124. package/dist/types/versions.d.ts.map +1 -0
  125. package/package.json +40 -20
  126. package/dist/__fixtures__/bytes.d.ts +0 -25
  127. package/dist/__fixtures__/bytes.js +0 -234
  128. package/dist/__fixtures__/bytes.js.map +0 -1
  129. package/dist/__fixtures__/coercions.d.ts +0 -5
  130. package/dist/__fixtures__/coercions.js +0 -22
  131. package/dist/__fixtures__/coercions.js.map +0 -1
  132. package/dist/__fixtures__/index.d.ts +0 -4
  133. package/dist/__fixtures__/index.js +0 -21
  134. package/dist/__fixtures__/index.js.map +0 -1
  135. package/dist/__fixtures__/json.d.ts +0 -1226
  136. package/dist/__fixtures__/json.js +0 -1491
  137. package/dist/__fixtures__/json.js.map +0 -1
  138. package/dist/__fixtures__/numbers.d.ts +0 -5
  139. package/dist/__fixtures__/numbers.js +0 -56
  140. package/dist/__fixtures__/numbers.js.map +0 -1
  141. package/dist/assert.js.map +0 -1
  142. package/dist/base64.js.map +0 -1
  143. package/dist/bytes.js.map +0 -1
  144. package/dist/checksum.js +0 -7
  145. package/dist/checksum.js.map +0 -1
  146. package/dist/coercers.js.map +0 -1
  147. package/dist/collections.js +0 -109
  148. package/dist/collections.js.map +0 -1
  149. package/dist/encryption-types.js +0 -3
  150. package/dist/encryption-types.js.map +0 -1
  151. package/dist/hex.js +0 -134
  152. package/dist/hex.js.map +0 -1
  153. package/dist/hex.test-d.d.ts +0 -1
  154. package/dist/hex.test-d.js +0 -16
  155. package/dist/hex.test-d.js.map +0 -1
  156. package/dist/index.js +0 -34
  157. package/dist/index.js.map +0 -1
  158. package/dist/json.js +0 -346
  159. package/dist/json.js.map +0 -1
  160. package/dist/json.test-d.d.ts +0 -1
  161. package/dist/json.test-d.js +0 -62
  162. package/dist/json.test-d.js.map +0 -1
  163. package/dist/keyring.js +0 -3
  164. package/dist/keyring.js.map +0 -1
  165. package/dist/logging.js.map +0 -1
  166. package/dist/misc.js.map +0 -1
  167. package/dist/misc.test-d.d.ts +0 -1
  168. package/dist/misc.test-d.js +0 -97
  169. package/dist/misc.test-d.js.map +0 -1
  170. package/dist/number.js.map +0 -1
  171. package/dist/opaque.js +0 -3
  172. package/dist/opaque.js.map +0 -1
  173. package/dist/time.js +0 -67
  174. package/dist/time.js.map +0 -1
  175. package/dist/transaction-types.js +0 -3
  176. package/dist/transaction-types.js.map +0 -1
  177. package/dist/versions.js +0 -95
  178. package/dist/versions.js.map +0 -1
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ createNumber: function() {
13
+ return createNumber;
14
+ },
15
+ createBigInt: function() {
16
+ return createBigInt;
17
+ },
18
+ createBytes: function() {
19
+ return createBytes;
20
+ },
21
+ createHex: function() {
22
+ return createHex;
23
+ }
24
+ });
25
+ const _superstruct = require("superstruct");
26
+ const _assert = require("./assert");
27
+ const _bytes = require("./bytes");
28
+ const _hex = require("./hex");
29
+ const NumberLikeStruct = (0, _superstruct.union)([
30
+ (0, _superstruct.number)(),
31
+ (0, _superstruct.bigint)(),
32
+ (0, _superstruct.string)(),
33
+ _hex.StrictHexStruct
34
+ ]);
35
+ const NumberCoercer = (0, _superstruct.coerce)((0, _superstruct.number)(), NumberLikeStruct, Number);
36
+ const BigIntCoercer = (0, _superstruct.coerce)((0, _superstruct.bigint)(), NumberLikeStruct, BigInt);
37
+ const BytesLikeStruct = (0, _superstruct.union)([
38
+ _hex.StrictHexStruct,
39
+ (0, _superstruct.instance)(Uint8Array)
40
+ ]);
41
+ const BytesCoercer = (0, _superstruct.coerce)((0, _superstruct.instance)(Uint8Array), (0, _superstruct.union)([
42
+ _hex.StrictHexStruct
43
+ ]), _bytes.hexToBytes);
44
+ const HexCoercer = (0, _superstruct.coerce)(_hex.StrictHexStruct, (0, _superstruct.instance)(Uint8Array), _bytes.bytesToHex);
45
+ function createNumber(value) {
46
+ try {
47
+ const result = (0, _superstruct.create)(value, NumberCoercer);
48
+ (0, _assert.assert)(Number.isFinite(result), `Expected a number-like value, got "${value}".`);
49
+ return result;
50
+ } catch (error) {
51
+ if (error instanceof _superstruct.StructError) {
52
+ throw new Error(`Expected a number-like value, got "${value}".`);
53
+ }
54
+ /* istanbul ignore next */ throw error;
55
+ }
56
+ }
57
+ function createBigInt(value) {
58
+ try {
59
+ // The `BigInt` constructor throws if the value is not a number-like value.
60
+ // There is no need to validate the value manually.
61
+ return (0, _superstruct.create)(value, BigIntCoercer);
62
+ } catch (error) {
63
+ if (error instanceof _superstruct.StructError) {
64
+ throw new Error(`Expected a number-like value, got "${String(error.value)}".`);
65
+ }
66
+ /* istanbul ignore next */ throw error;
67
+ }
68
+ }
69
+ function createBytes(value) {
70
+ if (typeof value === 'string' && value.toLowerCase() === '0x') {
71
+ return new Uint8Array();
72
+ }
73
+ try {
74
+ return (0, _superstruct.create)(value, BytesCoercer);
75
+ } catch (error) {
76
+ if (error instanceof _superstruct.StructError) {
77
+ throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
78
+ }
79
+ /* istanbul ignore next */ throw error;
80
+ }
81
+ }
82
+ function createHex(value) {
83
+ if (value instanceof Uint8Array && value.length === 0 || typeof value === 'string' && value.toLowerCase() === '0x') {
84
+ return '0x';
85
+ }
86
+ try {
87
+ return (0, _superstruct.create)(value, HexCoercer);
88
+ } catch (error) {
89
+ if (error instanceof _superstruct.StructError) {
90
+ throw new Error(`Expected a bytes-like value, got "${String(error.value)}".`);
91
+ }
92
+ /* istanbul ignore next */ throw error;
93
+ }
94
+ }
95
+
96
+ //# sourceMappingURL=coercers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/coercers.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport {\n bigint,\n coerce,\n create,\n instance,\n number,\n string,\n StructError,\n union,\n} from 'superstruct';\n\nimport { assert } from './assert';\nimport { bytesToHex, hexToBytes } from './bytes';\nimport type { Hex } from './hex';\nimport { StrictHexStruct } from './hex';\n\nconst NumberLikeStruct = union([number(), bigint(), string(), StrictHexStruct]);\nconst NumberCoercer = coerce(number(), NumberLikeStruct, Number);\nconst BigIntCoercer = coerce(bigint(), NumberLikeStruct, BigInt);\n\nconst BytesLikeStruct = union([StrictHexStruct, instance(Uint8Array)]);\nconst BytesCoercer = coerce(\n instance(Uint8Array),\n union([StrictHexStruct]),\n hexToBytes,\n);\n\nconst HexCoercer = coerce(StrictHexStruct, instance(Uint8Array), bytesToHex);\n\nexport type NumberLike = Infer<typeof NumberLikeStruct>;\nexport type BytesLike = Infer<typeof BytesLikeStruct>;\n\n/**\n * Create a number from a number-like value.\n *\n * - If the value is a number, it is returned as-is.\n * - If the value is a `bigint`, it is converted to a number.\n * - If the value is a string, it is interpreted as a decimal number.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number.\n *\n * This validates that the value is a number-like value, and that the resulting\n * number is not `NaN` or `Infinity`.\n *\n * @example\n * ```typescript\n * const value = createNumber('0x010203');\n * console.log(value); // 66051\n *\n * const otherValue = createNumber(123n);\n * console.log(otherValue); // 123\n * ```\n * @param value - The value to create the number from.\n * @returns The created number.\n * @throws If the value is not a number-like value, or if the resulting number\n * is `NaN` or `Infinity`.\n */\nexport function createNumber(value: NumberLike): number {\n try {\n const result = create(value, NumberCoercer);\n\n assert(\n Number.isFinite(result),\n `Expected a number-like value, got \"${value}\".`,\n );\n\n return result;\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(`Expected a number-like value, got \"${value}\".`);\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a `bigint` from a number-like value.\n *\n * - If the value is a number, it is converted to a `bigint`.\n * - If the value is a `bigint`, it is returned as-is.\n * - If the value is a string, it is interpreted as a decimal number and\n * converted to a `bigint`.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number and converted to a `bigint`.\n *\n * @example\n * ```typescript\n * const value = createBigInt('0x010203');\n * console.log(value); // 16909060n\n *\n * const otherValue = createBigInt(123);\n * console.log(otherValue); // 123n\n * ```\n * @param value - The value to create the bigint from.\n * @returns The created bigint.\n * @throws If the value is not a number-like value.\n */\nexport function createBigInt(value: NumberLike): bigint {\n try {\n // The `BigInt` constructor throws if the value is not a number-like value.\n // There is no need to validate the value manually.\n return create(value, BigIntCoercer);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Expected a number-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a byte array from a bytes-like value.\n *\n * - If the value is a byte array, it is returned as-is.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is interpreted\n * as a hexadecimal number and converted to a byte array.\n *\n * @example\n * ```typescript\n * const value = createBytes('0x010203');\n * console.log(value); // Uint8Array [ 1, 2, 3 ]\n *\n * const otherValue = createBytes('0x010203');\n * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]\n * ```\n * @param value - The value to create the byte array from.\n * @returns The created byte array.\n * @throws If the value is not a bytes-like value.\n */\nexport function createBytes(value: BytesLike): Uint8Array {\n if (typeof value === 'string' && value.toLowerCase() === '0x') {\n return new Uint8Array();\n }\n\n try {\n return create(value, BytesCoercer);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a hexadecimal string from a bytes-like value.\n *\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is returned\n * as-is.\n * - If the value is a `Uint8Array`, it is converted to a hex string.\n *\n * @example\n * ```typescript\n * const value = createHex(new Uint8Array([1, 2, 3]));\n * console.log(value); // '0x010203'\n *\n * const otherValue = createHex('0x010203');\n * console.log(otherValue); // '0x010203'\n * ```\n * @param value - The value to create the hex string from.\n * @returns The created hex string.\n * @throws If the value is not a bytes-like value.\n */\nexport function createHex(value: BytesLike): Hex {\n if (\n (value instanceof Uint8Array && value.length === 0) ||\n (typeof value === 'string' && value.toLowerCase() === '0x')\n ) {\n return '0x';\n }\n\n try {\n return create(value, HexCoercer);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n"],"names":["createNumber","createBigInt","createBytes","createHex","NumberLikeStruct","union","number","bigint","string","StrictHexStruct","NumberCoercer","coerce","Number","BigIntCoercer","BigInt","BytesLikeStruct","instance","Uint8Array","BytesCoercer","hexToBytes","HexCoercer","bytesToHex","value","result","create","assert","isFinite","error","StructError","Error","String","toLowerCase","length"],"mappings":";;;;;;;;;;;IA0DgBA,YAAY;eAAZA;;IA0CAC,YAAY;eAAZA;;IAoCAC,WAAW;eAAXA;;IAsCAC,SAAS;eAATA;;;6BApKT;wBAEgB;uBACgB;qBAEP;AAEhC,MAAMC,mBAAmBC,IAAAA,kBAAK,EAAC;IAACC,IAAAA,mBAAM;IAAIC,IAAAA,mBAAM;IAAIC,IAAAA,mBAAM;IAAIC,oBAAe;CAAC;AAC9E,MAAMC,gBAAgBC,IAAAA,mBAAM,EAACL,IAAAA,mBAAM,KAAIF,kBAAkBQ;AACzD,MAAMC,gBAAgBF,IAAAA,mBAAM,EAACJ,IAAAA,mBAAM,KAAIH,kBAAkBU;AAEzD,MAAMC,kBAAkBV,IAAAA,kBAAK,EAAC;IAACI,oBAAe;IAAEO,IAAAA,qBAAQ,EAACC;CAAY;AACrE,MAAMC,eAAeP,IAAAA,mBAAM,EACzBK,IAAAA,qBAAQ,EA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L,cAAcK,MAAMU,MAAM,KAAK,KAChD,OAAOV,UAAU,YAAYA,MAAMS,WAAW,OAAO,MACtD;QACA,OAAO;IACT;IAEA,IAAI;QACF,OAAOP,IAAAA,mBAAM,EAACF,OAAOF;IACvB,EAAE,OAAOO,OAAO;QACd,IAAIA,iBAAiBC,wBAAW,EAAE;YAChC,MAAM,IAAIC,MACR,CAAC,kCAAkC,EAAEC,OAAOH,MAAML,KAAK,EAAE,EAAE,CAAC;QAEhE;QAEA,wBAAwB,GACxB,MAAMK;IACR;AACF"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * A {@link ReadonlyMap} that cannot be modified after instantiation.
3
+ * The implementation uses an inner map hidden via a private field, and the
4
+ * immutability guarantee relies on it being impossible to get a reference
5
+ * to this map.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ function _export(target, all) {
11
+ for(var name in all)Object.defineProperty(target, name, {
12
+ enumerable: true,
13
+ get: all[name]
14
+ });
15
+ }
16
+ _export(exports, {
17
+ FrozenMap: function() {
18
+ return FrozenMap;
19
+ },
20
+ FrozenSet: function() {
21
+ return FrozenSet;
22
+ }
23
+ });
24
+ function _check_private_redeclaration(obj, privateCollection) {
25
+ if (privateCollection.has(obj)) {
26
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
27
+ }
28
+ }
29
+ function _class_apply_descriptor_get(receiver, descriptor) {
30
+ if (descriptor.get) {
31
+ return descriptor.get.call(receiver);
32
+ }
33
+ return descriptor.value;
34
+ }
35
+ function _class_apply_descriptor_set(receiver, descriptor, value) {
36
+ if (descriptor.set) {
37
+ descriptor.set.call(receiver, value);
38
+ } else {
39
+ if (!descriptor.writable) {
40
+ throw new TypeError("attempted to set read only private field");
41
+ }
42
+ descriptor.value = value;
43
+ }
44
+ }
45
+ function _class_extract_field_descriptor(receiver, privateMap, action) {
46
+ if (!privateMap.has(receiver)) {
47
+ throw new TypeError("attempted to " + action + " private field on non-instance");
48
+ }
49
+ return privateMap.get(receiver);
50
+ }
51
+ function _class_private_field_get(receiver, privateMap) {
52
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
53
+ return _class_apply_descriptor_get(receiver, descriptor);
54
+ }
55
+ function _class_private_field_init(obj, privateMap, value) {
56
+ _check_private_redeclaration(obj, privateMap);
57
+ privateMap.set(obj, value);
58
+ }
59
+ function _class_private_field_set(receiver, privateMap, value) {
60
+ var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
61
+ _class_apply_descriptor_set(receiver, descriptor, value);
62
+ return value;
63
+ }
64
+ var _map = /*#__PURE__*/ new WeakMap();
65
+ let _Symbol_iterator = Symbol.iterator;
66
+ class FrozenMap {
67
+ get size() {
68
+ return _class_private_field_get(this, _map).size;
69
+ }
70
+ [_Symbol_iterator]() {
71
+ return _class_private_field_get(this, _map)[Symbol.iterator]();
72
+ }
73
+ entries() {
74
+ return _class_private_field_get(this, _map).entries();
75
+ }
76
+ forEach(callbackfn, thisArg) {
77
+ // We have to wrap the specified callback in order to prevent it from
78
+ // receiving a reference to the inner map.
79
+ return _class_private_field_get(this, _map).forEach((value, key, _map)=>callbackfn.call(thisArg, value, key, this));
80
+ }
81
+ get(key) {
82
+ return _class_private_field_get(this, _map).get(key);
83
+ }
84
+ has(key) {
85
+ return _class_private_field_get(this, _map).has(key);
86
+ }
87
+ keys() {
88
+ return _class_private_field_get(this, _map).keys();
89
+ }
90
+ values() {
91
+ return _class_private_field_get(this, _map).values();
92
+ }
93
+ toString() {
94
+ return `FrozenMap(${this.size}) {${this.size > 0 ? ` ${[
95
+ ...this.entries()
96
+ ].map(([key, value])=>`${String(key)} => ${String(value)}`).join(', ')} ` : ''}}`;
97
+ }
98
+ constructor(entries){
99
+ _class_private_field_init(this, _map, {
100
+ writable: true,
101
+ value: void 0
102
+ });
103
+ _class_private_field_set(this, _map, new Map(entries));
104
+ Object.freeze(this);
105
+ }
106
+ }
107
+ var _set = /*#__PURE__*/ new WeakMap();
108
+ let _Symbol_iterator1 = Symbol.iterator;
109
+ /**
110
+ * A {@link ReadonlySet} that cannot be modified after instantiation.
111
+ * The implementation uses an inner set hidden via a private field, and the
112
+ * immutability guarantee relies on it being impossible to get a reference
113
+ * to this set.
114
+ */ class FrozenSet {
115
+ get size() {
116
+ return _class_private_field_get(this, _set).size;
117
+ }
118
+ [_Symbol_iterator1]() {
119
+ return _class_private_field_get(this, _set)[Symbol.iterator]();
120
+ }
121
+ entries() {
122
+ return _class_private_field_get(this, _set).entries();
123
+ }
124
+ forEach(callbackfn, thisArg) {
125
+ // We have to wrap the specified callback in order to prevent it from
126
+ // receiving a reference to the inner set.
127
+ return _class_private_field_get(this, _set).forEach((value, value2, _set)=>callbackfn.call(thisArg, value, value2, this));
128
+ }
129
+ has(value) {
130
+ return _class_private_field_get(this, _set).has(value);
131
+ }
132
+ keys() {
133
+ return _class_private_field_get(this, _set).keys();
134
+ }
135
+ values() {
136
+ return _class_private_field_get(this, _set).values();
137
+ }
138
+ toString() {
139
+ return `FrozenSet(${this.size}) {${this.size > 0 ? ` ${[
140
+ ...this.values()
141
+ ].map((member)=>String(member)).join(', ')} ` : ''}}`;
142
+ }
143
+ constructor(values){
144
+ _class_private_field_init(this, _set, {
145
+ writable: true,
146
+ value: void 0
147
+ });
148
+ _class_private_field_set(this, _set, new Set(values));
149
+ Object.freeze(this);
150
+ }
151
+ }
152
+ Object.freeze(FrozenMap);
153
+ Object.freeze(FrozenMap.prototype);
154
+ Object.freeze(FrozenSet);
155
+ Object.freeze(FrozenSet.prototype);
156
+
157
+ //# sourceMappingURL=collections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/collections.ts"],"sourcesContent":["/**\n * A {@link ReadonlyMap} that cannot be modified after instantiation.\n * The implementation uses an inner map hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this map.\n */\nclass FrozenMap<Key, Value> implements ReadonlyMap<Key, Value> {\n readonly #map: Map<Key, Value>;\n\n public get size() {\n return this.#map.size;\n }\n\n public [Symbol.iterator]() {\n return this.#map[Symbol.iterator]();\n }\n\n constructor(entries?: readonly (readonly [Key, Value])[] | null) {\n this.#map = new Map<Key, Value>(entries);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#map.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, key: Key, map: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner map.\n return this.#map.forEach((value: Value, key: Key, _map: unknown) =>\n callbackfn.call(thisArg, value, key, this),\n );\n }\n\n public get(key: Key) {\n return this.#map.get(key);\n }\n\n public has(key: Key) {\n return this.#map.has(key);\n }\n\n public keys() {\n return this.#map.keys();\n }\n\n public values() {\n return this.#map.values();\n }\n\n public toString(): string {\n return `FrozenMap(${this.size}) {${\n this.size > 0\n ? ` ${[...this.entries()]\n .map(([key, value]) => `${String(key)} => ${String(value)}`)\n .join(', ')} `\n : ''\n }}`;\n }\n}\n\n/**\n * A {@link ReadonlySet} that cannot be modified after instantiation.\n * The implementation uses an inner set hidden via a private field, and the\n * immutability guarantee relies on it being impossible to get a reference\n * to this set.\n */\nclass FrozenSet<Value> implements ReadonlySet<Value> {\n readonly #set: Set<Value>;\n\n public get size() {\n return this.#set.size;\n }\n\n public [Symbol.iterator]() {\n return this.#set[Symbol.iterator]();\n }\n\n constructor(values?: readonly Value[] | null) {\n this.#set = new Set<Value>(values);\n Object.freeze(this);\n }\n\n public entries() {\n return this.#set.entries();\n }\n\n public forEach(\n callbackfn: (value: Value, value2: Value, set: this) => void,\n thisArg?: any,\n ): void {\n // We have to wrap the specified callback in order to prevent it from\n // receiving a reference to the inner set.\n return this.#set.forEach((value: Value, value2: Value, _set: unknown) =>\n callbackfn.call(thisArg, value, value2, this),\n );\n }\n\n public has(value: Value) {\n return this.#set.has(value);\n }\n\n public keys() {\n return this.#set.keys();\n }\n\n public values() {\n return this.#set.values();\n }\n\n public toString(): string {\n return `FrozenSet(${this.size}) {${\n this.size > 0\n ? ` ${[...this.values()].map((member) => String(member)).join(', ')} `\n : ''\n }}`;\n }\n}\n\nObject.freeze(FrozenMap);\nObject.freeze(FrozenMap.prototype);\n\nObject.freeze(FrozenSet);\nObject.freeze(FrozenSet.prototype);\n\nexport { FrozenMap, FrozenSet };\n"],"names":["FrozenMap","FrozenSet","Symbol","iterator","size","map","entries","forEach","callbackfn","thisArg","value","key","_map","call","get","has","keys","values","toString","String","join","constructor","Map","Object","freeze","set","value2","_set","member","Set","prototype"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;IA2HQA,SAAS;eAATA;;IAAWC,SAAS;eAATA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAzHT;IAMDC,mBAAAA,OAAOC,QAAQ;AAPzB,MAAMH;IAGJ,IAAWI,OAAO;QAChB,OAAO,yBAAA,IAAI,EAAEC,MAAID,IAAI;IACvB;IAEO,CAACF,iBAAgB,GAAG;QACzB,OAAO,yBAAA,IAAI,EAAEG,KAAG,CAACH,OAAOC,QAAQ,CAAC;IACnC;IAOOG,UAAU;QACf,OAAO,yBAAA,IAAI,EAAED,MAAIC,OAAO;IAC1B;IAEOC,QACLC,UAAuD,EACvDC,OAAa,EACP;QACN,qEAAqE;QACrE,0CAA0C;QAC1C,OAAO,yBAAA,IAAI,EAAEJ,MAAIE,OAAO,CAAC,CAACG,OAAcC,KAAUC,OAChDJ,WAAWK,IAAI,CAACJ,SAASC,OAAOC,KAAK,IAAI;IAE7C;IAEOG,IAAIH,GAAQ,EAAE;QACnB,OAAO,yBAAA,IAAI,EAAEN,MAAIS,GAAG,CAACH;IACvB;IAEOI,IAAIJ,GAAQ,EAAE;QACnB,OAAO,yBAAA,IAAI,EAAEN,MAAIU,GAAG,CAACJ;IACvB;IAEOK,OAAO;QACZ,OAAO,yBAAA,IAAI,EAAEX,MAAIW,IAAI;IACvB;IAEOC,SAAS;QACd,OAAO,yBAAA,IAAI,EAAEZ,MAAIY,MAAM;IACzB;IAEOC,WAAmB;QACxB,O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ACd,IAAI,CAAC,GAAG,EAC/B,IAAI,CAACA,IAAI,GAAG,IACR,CAAC,CAAC,EAAE;eAAI,IAAI,CAACa,MAAM;SAAG,CAACZ,GAAG,CAAC,CAACuB,SAAWT,OAAOS,SAASR,IAAI,CAAC,MAAM,CAAC,CAAC,GACpE,GACL,CAAC,CAAC;IACL;IAtCAC,YAAYJ,MAAgC,CAAE;QAV9C,gCAAS;;mBAAT,KAAA;;uCAWQQ,MAAM,IAAII,IAAWZ;QAC3BM,OAAOC,MAAM,CAAC,IAAI;IACpB;AAoCF;AAEAD,OAAOC,MAAM,CAACxB;AACduB,OAAOC,MAAM,CAACxB,UAAU8B,SAAS;AAEjCP,OAAOC,MAAM,CAACvB;AACdsB,OAAOC,MAAM,CAACvB,UAAU6B,SAAS"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=encryption-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/encryption-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ HexStruct: function() {
13
+ return HexStruct;
14
+ },
15
+ StrictHexStruct: function() {
16
+ return StrictHexStruct;
17
+ },
18
+ HexAddressStruct: function() {
19
+ return HexAddressStruct;
20
+ },
21
+ HexChecksumAddressStruct: function() {
22
+ return HexChecksumAddressStruct;
23
+ },
24
+ isHexString: function() {
25
+ return isHexString;
26
+ },
27
+ isStrictHexString: function() {
28
+ return isStrictHexString;
29
+ },
30
+ assertIsHexString: function() {
31
+ return assertIsHexString;
32
+ },
33
+ assertIsStrictHexString: function() {
34
+ return assertIsStrictHexString;
35
+ },
36
+ isValidHexAddress: function() {
37
+ return isValidHexAddress;
38
+ },
39
+ getChecksumAddress: function() {
40
+ return getChecksumAddress;
41
+ },
42
+ isValidChecksumAddress: function() {
43
+ return isValidChecksumAddress;
44
+ },
45
+ add0x: function() {
46
+ return add0x;
47
+ },
48
+ remove0x: function() {
49
+ return remove0x;
50
+ }
51
+ });
52
+ const _sha3 = require("@noble/hashes/sha3");
53
+ const _superstruct = require("superstruct");
54
+ const _assert = require("./assert");
55
+ const _bytes = require("./bytes");
56
+ const HexStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), /^(?:0x)?[0-9a-f]+$/iu);
57
+ const StrictHexStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), /^0x[0-9a-f]+$/iu);
58
+ const HexAddressStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), /^0x[0-9a-f]{40}$/u);
59
+ const HexChecksumAddressStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), /^0x[0-9a-fA-F]{40}$/u);
60
+ function isHexString(value) {
61
+ return (0, _superstruct.is)(value, HexStruct);
62
+ }
63
+ function isStrictHexString(value) {
64
+ return (0, _superstruct.is)(value, StrictHexStruct);
65
+ }
66
+ function assertIsHexString(value) {
67
+ (0, _assert.assert)(isHexString(value), 'Value must be a hexadecimal string.');
68
+ }
69
+ function assertIsStrictHexString(value) {
70
+ (0, _assert.assert)(isStrictHexString(value), 'Value must be a hexadecimal string, starting with "0x".');
71
+ }
72
+ function isValidHexAddress(possibleAddress) {
73
+ return (0, _superstruct.is)(possibleAddress, HexAddressStruct) || isValidChecksumAddress(possibleAddress);
74
+ }
75
+ function getChecksumAddress(address) {
76
+ (0, _assert.assert)((0, _superstruct.is)(address, HexChecksumAddressStruct), 'Invalid hex address.');
77
+ const unPrefixed = remove0x(address.toLowerCase());
78
+ const unPrefixedHash = remove0x((0, _bytes.bytesToHex)((0, _sha3.keccak_256)(unPrefixed)));
79
+ return `0x${unPrefixed.split('').map((character, nibbleIndex)=>{
80
+ const hashCharacter = unPrefixedHash[nibbleIndex];
81
+ (0, _assert.assert)((0, _superstruct.is)(hashCharacter, (0, _superstruct.string)()), 'Hash shorter than address.');
82
+ return parseInt(hashCharacter, 16) > 7 ? character.toUpperCase() : character;
83
+ }).join('')}`;
84
+ }
85
+ function isValidChecksumAddress(possibleChecksum) {
86
+ if (!(0, _superstruct.is)(possibleChecksum, HexChecksumAddressStruct)) {
87
+ return false;
88
+ }
89
+ return getChecksumAddress(possibleChecksum) === possibleChecksum;
90
+ }
91
+ function add0x(hexadecimal) {
92
+ if (hexadecimal.startsWith('0x')) {
93
+ return hexadecimal;
94
+ }
95
+ if (hexadecimal.startsWith('0X')) {
96
+ return `0x${hexadecimal.substring(2)}`;
97
+ }
98
+ return `0x${hexadecimal}`;
99
+ }
100
+ function remove0x(hexadecimal) {
101
+ if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {
102
+ return hexadecimal.substring(2);
103
+ }
104
+ return hexadecimal;
105
+ }
106
+
107
+ //# sourceMappingURL=hex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hex.ts"],"sourcesContent":["import { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport type { Struct } from 'superstruct';\nimport { is, pattern, string } from 'superstruct';\n\nimport { assert } from './assert';\nimport { bytesToHex } from './bytes';\n\nexport type Hex = `0x${string}`;\n\nexport const HexStruct = pattern(string(), /^(?:0x)?[0-9a-f]+$/iu);\nexport const StrictHexStruct = pattern(string(), /^0x[0-9a-f]+$/iu) as Struct<\n Hex,\n null\n>;\nexport const HexAddressStruct = pattern(\n string(),\n /^0x[0-9a-f]{40}$/u,\n) as Struct<Hex, null>;\nexport const HexChecksumAddressStruct = pattern(\n string(),\n /^0x[0-9a-fA-F]{40}$/u,\n) as Struct<Hex, null>;\n\n/**\n * Check if a string is a valid hex string.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isHexString(value: unknown): value is string {\n return is(value, HexStruct);\n}\n\n/**\n * Strictly check if a string is a valid hex string. A valid hex string must\n * start with the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isStrictHexString(value: unknown): value is Hex {\n return is(value, StrictHexStruct);\n}\n\n/**\n * Assert that a value is a valid hex string.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsHexString(value: unknown): asserts value is string {\n assert(isHexString(value), 'Value must be a hexadecimal string.');\n}\n\n/**\n * Assert that a value is a valid hex string. A valid hex string must start with\n * the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsStrictHexString(value: unknown): asserts value is Hex {\n assert(\n isStrictHexString(value),\n 'Value must be a hexadecimal string, starting with \"0x\".',\n );\n}\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport function isValidHexAddress(possibleAddress: Hex) {\n return (\n is(possibleAddress, HexAddressStruct) ||\n isValidChecksumAddress(possibleAddress)\n );\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n *\n * @param address - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport function getChecksumAddress(address: Hex) {\n assert(is(address, HexChecksumAddressStruct), 'Invalid hex address.');\n const unPrefixed = remove0x(address.toLowerCase());\n const unPrefixedHash = remove0x(bytesToHex(keccak256(unPrefixed)));\n return `0x${unPrefixed\n .split('')\n .map((character, nibbleIndex) => {\n const hashCharacter = unPrefixedHash[nibbleIndex];\n assert(is(hashCharacter, string()), 'Hash shorter than address.');\n return parseInt(hashCharacter, 16) > 7\n ? character.toUpperCase()\n : character;\n })\n .join('')}`;\n}\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport function isValidChecksumAddress(possibleChecksum: Hex) {\n if (!is(possibleChecksum, HexChecksumAddressStruct)) {\n return false;\n }\n\n return getChecksumAddress(possibleChecksum) === possibleChecksum;\n}\n\n/**\n * Add the `0x`-prefix to a hexadecimal string. If the string already has the\n * prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to add the prefix to.\n * @returns The prefixed hexadecimal string.\n */\nexport function add0x(hexadecimal: string): Hex {\n if (hexadecimal.startsWith('0x')) {\n return hexadecimal as Hex;\n }\n\n if (hexadecimal.startsWith('0X')) {\n return `0x${hexadecimal.substring(2)}`;\n }\n\n return `0x${hexadecimal}`;\n}\n\n/**\n * Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have\n * the prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to remove the prefix from.\n * @returns The un-prefixed hexadecimal string.\n */\nexport function remove0x(hexadecimal: string): string {\n if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {\n return hexadecimal.substring(2);\n }\n\n return hexadecimal;\n}\n"],"names":["HexStruct","StrictHexStruct","HexAddressStruct","HexChecksumAddressStruct","isHexString","isStrictHexString","assertIsHexString","assertIsStrictHexString","isValidHexAddress","getChecksumAddress","isValidChecksumAddress","add0x","remove0x","pattern","string","value","is","assert","possibleAddress","address","unPrefixed","toLowerCase","unPrefixedHash","bytesToHex","keccak256","split","map","character","nibbleIndex","hashCharacter","parseInt","toUpperCase","join","possibleChecksum","hexadecimal","startsWith","substring"],"mappings":";;;;;;;;;;;IASaA,SAAS;eAATA;;IACAC,eAAe;eAAfA;;IAIAC,gBAAgB;eAAhBA;;IAIAC,wBAAwB;eAAxBA;;IAWGC,WAAW;eAAXA;;IAWAC,iBAAiB;eAAjBA;;IAUAC,iBAAiB;eAAjBA;;IAWAC,uBAAuB;eAAvBA;;IAcAC,iBAAiB;eAAjBA;;IAcAC,kBAAkB;eAAlBA;;IAuBAC,sBAAsB;eAAtBA;;IAeAC,KAAK;eAALA;;IAmBAC,QAAQ;eAARA;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ACjB,IAAAA,eAAE,EAACiB,kBAAkB9B,2BAA2B;QACnD,OAAO;IACT;IAEA,OAAOM,mBAAmBwB,sBAAsBA;AAClD;AASO,SAAStB,MAAMuB,WAAmB;IACvC,IAAIA,YAAYC,UAAU,CAAC,OAAO;QAChC,OAAOD;IACT;IAEA,IAAIA,YAAYC,UAAU,CAAC,OAAO;QAChC,OAAO,CAAC,EAAE,EAAED,YAAYE,SAAS,CAAC,GAAG,CAAC;IACxC;IAEA,OAAO,CAAC,EAAE,EAAEF,YAAY,CAAC;AAC3B;AASO,SAAStB,SAASsB,WAAmB;IAC1C,IAAIA,YAAYC,UAAU,CAAC,SAASD,YAAYC,UAAU,CAAC,OAAO;QAChE,OAAOD,YAAYE,SAAS,CAAC;IAC/B;IAEA,OAAOF;AACT"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./assert"), exports);
6
+ _export_star(require("./base64"), exports);
7
+ _export_star(require("./bytes"), exports);
8
+ _export_star(require("./caip-types"), exports);
9
+ _export_star(require("./checksum"), exports);
10
+ _export_star(require("./coercers"), exports);
11
+ _export_star(require("./collections"), exports);
12
+ _export_star(require("./encryption-types"), exports);
13
+ _export_star(require("./hex"), exports);
14
+ _export_star(require("./json"), exports);
15
+ _export_star(require("./keyring"), exports);
16
+ _export_star(require("./logging"), exports);
17
+ _export_star(require("./misc"), exports);
18
+ _export_star(require("./number"), exports);
19
+ _export_star(require("./opaque"), exports);
20
+ _export_star(require("./time"), exports);
21
+ _export_star(require("./transaction-types"), exports);
22
+ _export_star(require("./versions"), exports);
23
+ function _export_star(from, to) {
24
+ Object.keys(from).forEach(function(k) {
25
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
26
+ Object.defineProperty(to, k, {
27
+ enumerable: true,
28
+ get: function() {
29
+ return from[k];
30
+ }
31
+ });
32
+ }
33
+ });
34
+ return from;
35
+ }
36
+
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './assert';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caip-types';\nexport * from './checksum';\nexport * from './coercers';\nexport * from './collections';\nexport * from './encryption-types';\nexport * from './hex';\nexport * from './json';\nexport * from './keyring';\nexport * from './logging';\nexport * from './misc';\nexport * from './number';\nexport * from './opaque';\nexport * from './time';\nexport * from './transaction-types';\nexport * from './versions';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}