@xyo-network/bip39 2.72.9 → 2.73.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 (74) hide show
  1. package/dist/index.d.mts +77 -0
  2. package/dist/{types/index.d.ts → index.d.ts} +20 -8
  3. package/dist/index.js +18585 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +18544 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +28 -15
  8. package/tsup.config.ts +16 -0
  9. package/dist/cjs/index.js +0 -147
  10. package/dist/cjs/index.js.map +0 -1
  11. package/dist/cjs/wordlists/czech.js +0 -2053
  12. package/dist/cjs/wordlists/czech.js.map +0 -1
  13. package/dist/cjs/wordlists/english.js +0 -2053
  14. package/dist/cjs/wordlists/english.js.map +0 -1
  15. package/dist/cjs/wordlists/french.js +0 -2053
  16. package/dist/cjs/wordlists/french.js.map +0 -1
  17. package/dist/cjs/wordlists/index.js +0 -24
  18. package/dist/cjs/wordlists/index.js.map +0 -1
  19. package/dist/cjs/wordlists/italian.js +0 -2053
  20. package/dist/cjs/wordlists/italian.js.map +0 -1
  21. package/dist/cjs/wordlists/japanese.js +0 -2053
  22. package/dist/cjs/wordlists/japanese.js.map +0 -1
  23. package/dist/cjs/wordlists/korean.js +0 -2053
  24. package/dist/cjs/wordlists/korean.js.map +0 -1
  25. package/dist/cjs/wordlists/simplified-chinese.js +0 -2053
  26. package/dist/cjs/wordlists/simplified-chinese.js.map +0 -1
  27. package/dist/cjs/wordlists/spanish.js +0 -2053
  28. package/dist/cjs/wordlists/spanish.js.map +0 -1
  29. package/dist/cjs/wordlists/traditional-chinese.js +0 -2053
  30. package/dist/cjs/wordlists/traditional-chinese.js.map +0 -1
  31. package/dist/docs.json +0 -1057
  32. package/dist/esm/index.js +0 -137
  33. package/dist/esm/index.js.map +0 -1
  34. package/dist/esm/wordlists/czech.js +0 -2050
  35. package/dist/esm/wordlists/czech.js.map +0 -1
  36. package/dist/esm/wordlists/english.js +0 -2050
  37. package/dist/esm/wordlists/english.js.map +0 -1
  38. package/dist/esm/wordlists/french.js +0 -2050
  39. package/dist/esm/wordlists/french.js.map +0 -1
  40. package/dist/esm/wordlists/index.js +0 -21
  41. package/dist/esm/wordlists/index.js.map +0 -1
  42. package/dist/esm/wordlists/italian.js +0 -2050
  43. package/dist/esm/wordlists/italian.js.map +0 -1
  44. package/dist/esm/wordlists/japanese.js +0 -2050
  45. package/dist/esm/wordlists/japanese.js.map +0 -1
  46. package/dist/esm/wordlists/korean.js +0 -2050
  47. package/dist/esm/wordlists/korean.js.map +0 -1
  48. package/dist/esm/wordlists/simplified-chinese.js +0 -2050
  49. package/dist/esm/wordlists/simplified-chinese.js.map +0 -1
  50. package/dist/esm/wordlists/spanish.js +0 -2050
  51. package/dist/esm/wordlists/spanish.js.map +0 -1
  52. package/dist/esm/wordlists/traditional-chinese.js +0 -2050
  53. package/dist/esm/wordlists/traditional-chinese.js.map +0 -1
  54. package/dist/types/index.d.ts.map +0 -1
  55. package/dist/types/wordlists/czech.d.ts +0 -2
  56. package/dist/types/wordlists/czech.d.ts.map +0 -1
  57. package/dist/types/wordlists/english.d.ts +0 -2
  58. package/dist/types/wordlists/english.d.ts.map +0 -1
  59. package/dist/types/wordlists/french.d.ts +0 -2
  60. package/dist/types/wordlists/french.d.ts.map +0 -1
  61. package/dist/types/wordlists/index.d.ts +0 -12
  62. package/dist/types/wordlists/index.d.ts.map +0 -1
  63. package/dist/types/wordlists/italian.d.ts +0 -2
  64. package/dist/types/wordlists/italian.d.ts.map +0 -1
  65. package/dist/types/wordlists/japanese.d.ts +0 -2
  66. package/dist/types/wordlists/japanese.d.ts.map +0 -1
  67. package/dist/types/wordlists/korean.d.ts +0 -2
  68. package/dist/types/wordlists/korean.d.ts.map +0 -1
  69. package/dist/types/wordlists/simplified-chinese.d.ts +0 -2
  70. package/dist/types/wordlists/simplified-chinese.d.ts.map +0 -1
  71. package/dist/types/wordlists/spanish.d.ts +0 -2
  72. package/dist/types/wordlists/spanish.d.ts.map +0 -1
  73. package/dist/types/wordlists/traditional-chinese.d.ts +0 -2
  74. package/dist/types/wordlists/traditional-chinese.d.ts.map +0 -1
package/package.json CHANGED
@@ -15,41 +15,54 @@
15
15
  },
16
16
  "description": "Primary SDK for using XYO Protocol 2.0",
17
17
  "devDependencies": {
18
- "@xylabs/ts-scripts-yarn3": "^2.19.3",
19
- "@xylabs/tsconfig": "^2.19.3",
18
+ "@xylabs/ts-scripts-yarn3": "^2.19.5",
19
+ "@xylabs/tsconfig": "^2.19.5",
20
+ "publint": "^0.2.2",
21
+ "tsup": "^7.2.0",
20
22
  "typescript": "^5.2.2"
21
23
  },
22
- "browser": "dist/esm/index.js",
23
- "main": "dist/cjs/index.js",
24
- "module": "dist/esm/index.js",
25
24
  "docs": "dist/docs.json",
26
25
  "exports": {
27
26
  ".": {
28
- "node": {
29
- "import": "./dist/esm/index.js",
30
- "require": "./dist/cjs/index.js"
27
+ "require": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
31
30
  },
32
- "browser": {
33
- "import": "./dist/esm/index.js",
34
- "require": "./dist/cjs/index.js"
35
- },
36
- "default": "./dist/esm/index.js"
31
+ "import": {
32
+ "types": "./dist/index.d.mts",
33
+ "default": "./dist/index.mjs"
34
+ }
37
35
  },
38
36
  "./dist/docs.json": {
39
37
  "default": "./dist/docs.json"
40
38
  },
39
+ "./cjs": {
40
+ "default": "./dist/index.js"
41
+ },
42
+ "./docs": {
43
+ "default": "./dist/docs.json"
44
+ },
45
+ "./esm": {
46
+ "default": "./dist/index.mjs"
47
+ },
41
48
  "./package.json": "./package.json"
42
49
  },
50
+ "main": "dist/index.js",
51
+ "module": "dist/index.mjs",
43
52
  "homepage": "https://xyo.network",
44
53
  "license": "LGPL-3.0",
45
54
  "publishConfig": {
46
55
  "access": "public"
47
56
  },
57
+ "scripts": {
58
+ "package-compile": "tsup && publint",
59
+ "package-recompile": "tsup && publint"
60
+ },
48
61
  "repository": {
49
62
  "type": "git",
50
63
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
51
64
  },
52
65
  "sideEffects": false,
53
- "types": "dist/types/index.d.ts",
54
- "version": "2.72.9"
66
+ "types": "dist/index.d.ts",
67
+ "version": "2.73.0"
55
68
  }
package/tsup.config.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'tsup'
2
+
3
+ // eslint-disable-next-line import/no-default-export
4
+ export default defineConfig({
5
+ bundle: true,
6
+ cjsInterop: true,
7
+ clean: true,
8
+ dts: {
9
+ entry: ['src/index.ts'],
10
+ },
11
+ entry: ['src/index.ts'],
12
+ format: ['cjs', 'esm'],
13
+ sourcemap: true,
14
+ splitting: false,
15
+ tsconfig: 'tsconfig.json',
16
+ })
package/dist/cjs/index.js DELETED
@@ -1,147 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mnemonicToSeedSync = exports.mnemonicToSeed = exports.validateMnemonic = exports.entropyToMnemonic = exports.mnemonicToEntropy = exports.generateMnemonic = void 0;
4
- const tslib_1 = require("tslib");
5
- /* eslint-disable import/no-named-as-default-member */
6
- /* eslint-disable import/no-internal-modules */
7
- /*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */
8
- const _assert_1 = tslib_1.__importDefault(require("@noble/hashes/_assert"));
9
- const pbkdf2_1 = require("@noble/hashes/pbkdf2");
10
- const sha256_1 = require("@noble/hashes/sha256");
11
- const sha512_1 = require("@noble/hashes/sha512");
12
- const utils_1 = require("@noble/hashes/utils");
13
- const base_1 = require("@scure/base");
14
- tslib_1.__exportStar(require("./wordlists"), exports);
15
- // Japanese wordlist
16
- const isJapanese = (wordlist) => wordlist[0] === '\u3042\u3044\u3053\u304f\u3057\u3093';
17
- // Normalization replaces equivalent sequences of characters
18
- // so that any two texts that are equivalent will be reduced
19
- // to the same sequence of code points, called the normal form of the original text.
20
- function nfkd(str) {
21
- if (typeof str !== 'string')
22
- throw new TypeError(`Invalid mnemonic type: ${typeof str}`);
23
- return str.normalize('NFKD');
24
- }
25
- function normalize(str) {
26
- const norm = nfkd(str);
27
- const words = norm.split(' ');
28
- if (![12, 15, 18, 21, 24].includes(words.length))
29
- throw new Error('Invalid mnemonic');
30
- return { nfkd: norm, words };
31
- }
32
- function assertEntropy(entropy) {
33
- _assert_1.default.bytes(entropy, 16, 20, 24, 28, 32);
34
- }
35
- /**
36
- * Generate x random words. Uses Cryptographically-Secure Random Number Generator.
37
- * @param wordlist imported wordlist for specific language
38
- * @param strength mnemonic strength 128-256 bits
39
- * @example
40
- * generateMnemonic(wordlist, 128)
41
- * // 'legal winner thank year wave sausage worth useful legal winner thank yellow'
42
- */
43
- function generateMnemonic(wordlist, strength = 128) {
44
- _assert_1.default.number(strength);
45
- if (strength % 32 !== 0 || strength > 256)
46
- throw new TypeError('Invalid entropy');
47
- return entropyToMnemonic((0, utils_1.randomBytes)(strength / 8), wordlist);
48
- }
49
- exports.generateMnemonic = generateMnemonic;
50
- const calcChecksum = (entropy) => {
51
- // Checksum is ent.length/4 bits long
52
- const bitsLeft = 8 - entropy.length / 4;
53
- // Zero rightmost "bitsLeft" bits in byte
54
- // For example: bitsLeft=4 val=10111101 -> 10110000
55
- return new Uint8Array([((0, sha256_1.sha256)(entropy)[0] >> bitsLeft) << bitsLeft]);
56
- };
57
- function getCoder(wordlist) {
58
- if (!Array.isArray(wordlist) || wordlist.length !== 2048 || typeof wordlist[0] !== 'string')
59
- throw new Error('Worlist: expected array of 2048 strings');
60
- wordlist.forEach((i) => {
61
- if (typeof i !== 'string')
62
- throw new Error(`Wordlist: non-string element: ${i}`);
63
- });
64
- return base_1.utils.chain(base_1.utils.checksum(1, calcChecksum), base_1.utils.radix2(11, true), base_1.utils.alphabet(wordlist));
65
- }
66
- /**
67
- * Reversible: Converts mnemonic string to raw entropy in form of byte array.
68
- * @param mnemonic 12-24 words
69
- * @param wordlist imported wordlist for specific language
70
- * @example
71
- * const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
72
- * mnemonicToEntropy(mnem, wordlist)
73
- * // Produces
74
- * new Uint8Array([
75
- * 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
76
- * 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
77
- * ])
78
- */
79
- function mnemonicToEntropy(mnemonic, wordlist) {
80
- const { words } = normalize(mnemonic);
81
- const entropy = getCoder(wordlist).decode(words);
82
- assertEntropy(entropy);
83
- return entropy;
84
- }
85
- exports.mnemonicToEntropy = mnemonicToEntropy;
86
- /**
87
- * Reversible: Converts raw entropy in form of byte array to mnemonic string.
88
- * @param entropy byte array
89
- * @param wordlist imported wordlist for specific language
90
- * @returns 12-24 words
91
- * @example
92
- * const ent = new Uint8Array([
93
- * 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
94
- * 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
95
- * ]);
96
- * entropyToMnemonic(ent, wordlist);
97
- * // 'legal winner thank year wave sausage worth useful legal winner thank yellow'
98
- */
99
- function entropyToMnemonic(entropy, wordlist) {
100
- assertEntropy(entropy);
101
- const words = getCoder(wordlist).encode(entropy);
102
- return words.join(isJapanese(wordlist) ? '\u3000' : ' ');
103
- }
104
- exports.entropyToMnemonic = entropyToMnemonic;
105
- /**
106
- * Validates mnemonic for being 12-24 words contained in `wordlist`.
107
- */
108
- function validateMnemonic(mnemonic, wordlist) {
109
- try {
110
- mnemonicToEntropy(mnemonic, wordlist);
111
- }
112
- catch (e) {
113
- return false;
114
- }
115
- return true;
116
- }
117
- exports.validateMnemonic = validateMnemonic;
118
- const salt = (passphrase) => nfkd(`mnemonic${passphrase}`);
119
- /**
120
- * Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.
121
- * @param mnemonic 12-24 words
122
- * @param passphrase string that will additionally protect the key
123
- * @returns 64 bytes of key data
124
- * @example
125
- * const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
126
- * await mnemonicToSeed(mnem, 'password');
127
- * // new Uint8Array([...64 bytes])
128
- */
129
- function mnemonicToSeed(mnemonic, passphrase = '') {
130
- return (0, pbkdf2_1.pbkdf2Async)(sha512_1.sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
131
- }
132
- exports.mnemonicToSeed = mnemonicToSeed;
133
- /**
134
- * Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.
135
- * @param mnemonic 12-24 words
136
- * @param passphrase string that will additionally protect the key
137
- * @returns 64 bytes of key data
138
- * @example
139
- * const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
140
- * mnemonicToSeedSync(mnem, 'password');
141
- * // new Uint8Array([...64 bytes])
142
- */
143
- function mnemonicToSeedSync(mnemonic, passphrase = '') {
144
- return (0, pbkdf2_1.pbkdf2)(sha512_1.sha512, normalize(mnemonic).nfkd, salt(passphrase), { c: 2048, dkLen: 64 });
145
- }
146
- exports.mnemonicToSeedSync = mnemonicToSeedSync;
147
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,sDAAsD;AACtD,+CAA+C;AAC/C,yFAAyF;AACzF,4EAA0C;AAC1C,iDAA0D;AAC1D,iDAA6C;AAC7C,iDAA6C;AAC7C,+CAAiD;AACjD,sCAAgD;AAEhD,sDAA2B;AAE3B,oBAAoB;AACpB,MAAM,UAAU,GAAG,CAAC,QAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,sCAAsC,CAAA;AAEjG,4DAA4D;AAC5D,4DAA4D;AAC5D,oFAAoF;AACpF,SAAS,IAAI,CAAC,GAAW;IACvB,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,MAAM,IAAI,SAAS,CAAC,0BAA0B,OAAO,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