multichain-address-validator 0.8.1 → 0.8.3

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,5 +1,5 @@
1
1
  declare const _default: {
2
- b32decode: (s: string) => Uint8Array;
2
+ b32decode: (s: string) => Uint8Array<ArrayBuffer>;
3
3
  b32encode: (s: string) => string;
4
4
  };
5
5
  export default _default;
@@ -2,8 +2,8 @@ export default Blake2b;
2
2
  declare function Blake2b(outlen: any, key: any, salt: any, personal: any): void;
3
3
  declare class Blake2b {
4
4
  constructor(outlen: any, key: any, salt: any, personal: any);
5
- b: Uint8Array;
6
- h: Uint32Array;
5
+ b: Uint8Array<ArrayBuffer>;
6
+ h: Uint32Array<ArrayBuffer>;
7
7
  t: number;
8
8
  c: number;
9
9
  outlen: any;
@@ -1,6 +1,6 @@
1
1
  declare function numberToHex(number: number, length: number): string;
2
2
  declare function byteArray2hexStr(byteArray: number[]): string;
3
- declare function hexStr2byteArray(str: string): Uint8Array;
3
+ declare function hexStr2byteArray(str: string): Uint8Array<ArrayBuffer>;
4
4
  declare const _default: {
5
5
  numberToHex: typeof numberToHex;
6
6
  toHex: (arrayOfBytes: any) => string;
@@ -12,14 +12,14 @@ declare const _default: {
12
12
  blake256: (hexString: string) => string;
13
13
  blake256Checksum: (payload: any) => any;
14
14
  blake2b: (hexString: string, outlen: number) => any;
15
- keccak256: (hexString: string) => string;
15
+ keccak256: (input: string | Uint8Array) => string;
16
16
  keccak256Checksum: (payload: any) => any;
17
17
  blake2b256: (hexString: string) => any;
18
18
  base58: (string: string) => number[];
19
19
  byteArray2hexStr: typeof byteArray2hexStr;
20
20
  hexStr2byteArray: typeof hexStr2byteArray;
21
21
  base32: {
22
- b32decode: (s: string) => Uint8Array;
22
+ b32decode: (s: string) => Uint8Array<ArrayBuffer>;
23
23
  b32encode: (s: string) => string;
24
24
  };
25
25
  };
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const buffer_1 = require("buffer");
7
- const sha256_1 = require("@noble/hashes/sha256");
8
- const sha512_1 = require("@noble/hashes/sha512");
9
- const utils_1 = require("@noble/hashes/utils");
10
- const sha3_1 = require("@noble/hashes/sha3");
7
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
8
+ const sha2_js_2 = require("@noble/hashes/sha2.js");
9
+ const utils_js_1 = require("@noble/hashes/utils.js");
10
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
11
11
  const base32_js_1 = __importDefault(require("./base32.js"));
12
12
  const base58_js_1 = __importDefault(require("./base58.js"));
13
13
  const blake256_js_1 = __importDefault(require("./blake256.js"));
@@ -89,7 +89,7 @@ exports.default = {
89
89
  return hex;
90
90
  },
91
91
  sha256: function (payload, format = 'HEX') {
92
- return (0, utils_1.bytesToHex)((0, sha256_1.sha256)(hexStr2byteArray(payload)));
92
+ return (0, utils_js_1.bytesToHex)((0, sha2_js_1.sha256)(hexStr2byteArray(payload)));
93
93
  },
94
94
  sha256x2: function (buffer, format = 'HEX') {
95
95
  return this.sha256(this.sha256(buffer, format), format);
@@ -98,10 +98,10 @@ exports.default = {
98
98
  return this.sha256(this.sha256(payload)).slice(0, 8);
99
99
  },
100
100
  sha512: function (payload, format = 'HEX') {
101
- return (0, utils_1.bytesToHex)((0, sha512_1.sha512)(payload));
101
+ return (0, utils_js_1.bytesToHex)((0, sha2_js_2.sha512)(payload instanceof Uint8Array ? payload : hexStr2byteArray(payload)));
102
102
  },
103
103
  sha512_256: function (payload, format = 'HEX') {
104
- return (0, utils_1.bytesToHex)((0, sha512_1.sha512_256)(hexStr2byteArray(payload)));
104
+ return (0, utils_js_1.bytesToHex)((0, sha2_js_2.sha512_256)(hexStr2byteArray(payload)));
105
105
  },
106
106
  blake256: function (hexString) {
107
107
  return new blake256_js_1.default().update(hexString, 'hex').digest('hex');
@@ -112,8 +112,9 @@ exports.default = {
112
112
  blake2b: function (hexString, outlen) {
113
113
  return new blake2b_js_1.default(outlen).update(buffer_1.Buffer.from(hexString, 'hex')).digest('hex');
114
114
  },
115
- keccak256: function (hexString) {
116
- return (0, utils_1.bytesToHex)((0, sha3_1.keccak_256)(hexString));
115
+ keccak256: function (input) {
116
+ const data = typeof input === 'string' ? new TextEncoder().encode(input) : input;
117
+ return (0, utils_js_1.bytesToHex)((0, sha3_js_1.keccak_256)(data));
117
118
  },
118
119
  keccak256Checksum: function (payload) {
119
120
  return this.keccak256(payload).toString().substr(0, 8);
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const base_x_1 = __importDefault(require("base-x"));
7
+ const buffer_1 = require("buffer");
7
8
  const crc_1 = __importDefault(require("crc"));
8
9
  const utils_js_1 = __importDefault(require("../crypto/utils.js"));
9
10
  const helpers_js_1 = require("../helpers.js");
@@ -39,7 +40,7 @@ exports.default = {
39
40
  if (bytes[0] !== ed25519PublicKeyVersionByte) {
40
41
  return false;
41
42
  }
42
- const computedChecksum = utils_js_1.default.numberToHex(swap16(crc_1.default.crc16xmodem(bytes.slice(0, -2))), 4);
43
+ const computedChecksum = utils_js_1.default.numberToHex(swap16(crc_1.default.crc16xmodem(buffer_1.Buffer.from(bytes.slice(0, -2)))), 4);
43
44
  const checksum = utils_js_1.default.toHex(bytes.slice(-2));
44
45
  return computedChecksum === checksum;
45
46
  }
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
- b32decode: (s: string) => Uint8Array;
2
+ b32decode: (s: string) => Uint8Array<ArrayBuffer>;
3
3
  b32encode: (s: string) => string;
4
4
  };
5
5
  export default _default;
@@ -2,8 +2,8 @@ export default Blake2b;
2
2
  declare function Blake2b(outlen: any, key: any, salt: any, personal: any): void;
3
3
  declare class Blake2b {
4
4
  constructor(outlen: any, key: any, salt: any, personal: any);
5
- b: Uint8Array;
6
- h: Uint32Array;
5
+ b: Uint8Array<ArrayBuffer>;
6
+ h: Uint32Array<ArrayBuffer>;
7
7
  t: number;
8
8
  c: number;
9
9
  outlen: any;
@@ -1,6 +1,6 @@
1
1
  declare function numberToHex(number: number, length: number): string;
2
2
  declare function byteArray2hexStr(byteArray: number[]): string;
3
- declare function hexStr2byteArray(str: string): Uint8Array;
3
+ declare function hexStr2byteArray(str: string): Uint8Array<ArrayBuffer>;
4
4
  declare const _default: {
5
5
  numberToHex: typeof numberToHex;
6
6
  toHex: (arrayOfBytes: any) => string;
@@ -12,14 +12,14 @@ declare const _default: {
12
12
  blake256: (hexString: string) => string;
13
13
  blake256Checksum: (payload: any) => any;
14
14
  blake2b: (hexString: string, outlen: number) => any;
15
- keccak256: (hexString: string) => string;
15
+ keccak256: (input: string | Uint8Array) => string;
16
16
  keccak256Checksum: (payload: any) => any;
17
17
  blake2b256: (hexString: string) => any;
18
18
  base58: (string: string) => number[];
19
19
  byteArray2hexStr: typeof byteArray2hexStr;
20
20
  hexStr2byteArray: typeof hexStr2byteArray;
21
21
  base32: {
22
- b32decode: (s: string) => Uint8Array;
22
+ b32decode: (s: string) => Uint8Array<ArrayBuffer>;
23
23
  b32encode: (s: string) => string;
24
24
  };
25
25
  };
@@ -1,8 +1,8 @@
1
1
  import { Buffer } from 'buffer';
2
- import { sha256 } from '@noble/hashes/sha256';
3
- import { sha512, sha512_256 } from '@noble/hashes/sha512';
4
- import { bytesToHex } from '@noble/hashes/utils';
5
- import { keccak_256 } from '@noble/hashes/sha3';
2
+ import { sha256 } from '@noble/hashes/sha2.js';
3
+ import { sha512, sha512_256 } from '@noble/hashes/sha2.js';
4
+ import { bytesToHex } from '@noble/hashes/utils.js';
5
+ import { keccak_256 } from '@noble/hashes/sha3.js';
6
6
  import base32 from './base32.js';
7
7
  import base58 from './base58.js';
8
8
  import Blake256 from './blake256.js';
@@ -93,7 +93,7 @@ export default {
93
93
  return this.sha256(this.sha256(payload)).slice(0, 8);
94
94
  },
95
95
  sha512: function (payload, format = 'HEX') {
96
- return bytesToHex(sha512(payload));
96
+ return bytesToHex(sha512(payload instanceof Uint8Array ? payload : hexStr2byteArray(payload)));
97
97
  },
98
98
  sha512_256: function (payload, format = 'HEX') {
99
99
  return bytesToHex(sha512_256(hexStr2byteArray(payload)));
@@ -107,8 +107,9 @@ export default {
107
107
  blake2b: function (hexString, outlen) {
108
108
  return new Blake2B(outlen).update(Buffer.from(hexString, 'hex')).digest('hex');
109
109
  },
110
- keccak256: function (hexString) {
111
- return bytesToHex(keccak_256(hexString));
110
+ keccak256: function (input) {
111
+ const data = typeof input === 'string' ? new TextEncoder().encode(input) : input;
112
+ return bytesToHex(keccak_256(data));
112
113
  },
113
114
  keccak256Checksum: function (payload) {
114
115
  return this.keccak256(payload).toString().substr(0, 8);
@@ -1,4 +1,5 @@
1
1
  import baseX from 'base-x';
2
+ import { Buffer } from 'buffer';
2
3
  import crc from 'crc';
3
4
  import cryptoUtils from '../crypto/utils.js';
4
5
  import { getAddress, getMemo } from '../helpers.js';
@@ -34,7 +35,7 @@ export default {
34
35
  if (bytes[0] !== ed25519PublicKeyVersionByte) {
35
36
  return false;
36
37
  }
37
- const computedChecksum = cryptoUtils.numberToHex(swap16(crc.crc16xmodem(bytes.slice(0, -2))), 4);
38
+ const computedChecksum = cryptoUtils.numberToHex(swap16(crc.crc16xmodem(Buffer.from(bytes.slice(0, -2)))), 4);
38
39
  const checksum = cryptoUtils.toHex(bytes.slice(-2));
39
40
  return computedChecksum === checksum;
40
41
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "multichain-address-validator",
3
3
  "description": "Multichain address validator for Bitcoin and other blockchains.",
4
- "version": "0.8.1",
4
+ "version": "0.8.3",
5
5
  "keywords": [
6
6
  "0x",
7
7
  "zrx",
@@ -348,17 +348,21 @@
348
348
  "release": "node scripts/release.mjs"
349
349
  },
350
350
  "dependencies": {
351
- "@noble/hashes": "^1.4.0",
352
- "base-x": "^4.0.0",
353
- "buffer": "^6.0.3",
354
- "cbor-js": "^0.1.0",
355
- "crc": "^4.3.2",
356
- "lodash.isequal": "^4.5.0"
351
+ "@noble/hashes": "2.0.1",
352
+ "base-x": "5.0.1",
353
+ "buffer": "6.0.3",
354
+ "cbor-js": "0.1.0",
355
+ "crc": "4.3.2",
356
+ "lodash.isequal": "4.5.0"
357
357
  },
358
358
  "devDependencies": {
359
- "chai": "^4.4.1",
360
- "mocha": "^10.2.0",
361
- "tsx": "^4.16.2",
362
- "typescript": "^5.5.4"
359
+ "chai": "6.2.2",
360
+ "mocha": "11.7.5",
361
+ "tsx": "4.21.0",
362
+ "typescript": "6.0.2"
363
+ },
364
+ "overrides": {
365
+ "serialize-javascript": "7.0.5",
366
+ "diff": "8.0.3"
363
367
  }
364
368
  }