@chainflip/utils 0.2.1 → 0.4.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.
package/dist/math.cjs ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/math.ts
21
+ var math_exports = {};
22
+ __export(math_exports, {
23
+ average: () => average,
24
+ sum: () => sum
25
+ });
26
+ module.exports = __toCommonJS(math_exports);
27
+ var sum = (arr) => arr.reduce((a, b) => a + b, 0);
28
+ var average = (arr) => sum(arr) / arr.length;
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ average,
32
+ sum
33
+ });
@@ -0,0 +1,4 @@
1
+ declare const sum: (arr: number[]) => number;
2
+ declare const average: (arr: number[]) => number;
3
+
4
+ export { average, sum };
package/dist/math.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare const sum: (arr: number[]) => number;
2
+ declare const average: (arr: number[]) => number;
3
+
4
+ export { average, sum };
package/dist/math.js ADDED
@@ -0,0 +1,7 @@
1
+ // src/math.ts
2
+ var sum = (arr) => arr.reduce((a, b) => a + b, 0);
3
+ var average = (arr) => sum(arr) / arr.length;
4
+ export {
5
+ average,
6
+ sum
7
+ };
package/dist/ss58.cjs CHANGED
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var ss58_exports = {};
22
22
  __export(ss58_exports, {
23
23
  decode: () => decode2,
24
- encode: () => encode2
24
+ encode: () => encode2,
25
+ toPublicKey: () => toPublicKey
25
26
  });
26
27
  module.exports = __toCommonJS(ss58_exports);
27
28
 
@@ -642,6 +643,10 @@ var BLAKE2b = class extends BLAKE {
642
643
  var blake2b = /* @__PURE__ */ wrapConstructorWithOpts((opts) => new BLAKE2b(opts));
643
644
 
644
645
  // src/bytes.ts
646
+ var bytesToHex = (input) => {
647
+ const bytes2 = new Uint8Array(input);
648
+ return `0x${Array.from(bytes2).map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
649
+ };
645
650
  var hexToBytes = (input) => {
646
651
  assert(/^0x[\da-f]*$/i.test(input) && input.length % 2 === 0, "Invalid hex string");
647
652
  const hex = input.slice(2);
@@ -745,10 +750,12 @@ var encode2 = ({
745
750
  const checksum = computeChecksum(new Uint8Array([...prefixBytes, ...data]));
746
751
  return encode([...prefixBytes, ...data, ...checksum]);
747
752
  };
753
+ var toPublicKey = (address) => bytesToHex(decode2(address).data);
748
754
  // Annotate the CommonJS export names for ESM import in node:
749
755
  0 && (module.exports = {
750
756
  decode,
751
- encode
757
+ encode,
758
+ toPublicKey
752
759
  });
753
760
  /*! Bundled license information:
754
761
 
package/dist/ss58.d.cts CHANGED
@@ -8,5 +8,6 @@ declare const encode: ({ data: input, ss58Format, }: {
8
8
  data: Uint8Array | HexString;
9
9
  ss58Format: number;
10
10
  }) => string;
11
+ declare const toPublicKey: (address: string) => HexString;
11
12
 
12
- export { decode, encode };
13
+ export { decode, encode, toPublicKey };
package/dist/ss58.d.ts CHANGED
@@ -8,5 +8,6 @@ declare const encode: ({ data: input, ss58Format, }: {
8
8
  data: Uint8Array | HexString;
9
9
  ss58Format: number;
10
10
  }) => string;
11
+ declare const toPublicKey: (address: string) => HexString;
11
12
 
12
- export { decode, encode };
13
+ export { decode, encode, toPublicKey };
package/dist/ss58.js CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  encode
4
4
  } from "./chunk-UPA7KLTI.js";
5
5
  import {
6
+ bytesToHex,
6
7
  hexToBytes
7
8
  } from "./chunk-D7RIA7SA.js";
8
9
  import {
@@ -669,9 +670,11 @@ var encode2 = ({
669
670
  const checksum = computeChecksum(new Uint8Array([...prefixBytes, ...data]));
670
671
  return encode([...prefixBytes, ...data, ...checksum]);
671
672
  };
673
+ var toPublicKey = (address) => bytesToHex(decode2(address).data);
672
674
  export {
673
675
  decode2 as decode,
674
- encode2 as encode
676
+ encode2 as encode,
677
+ toPublicKey
675
678
  };
676
679
  /*! Bundled license information:
677
680
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/utils",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",