@metamask/keyring-sdk 3.0.0 → 3.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.1.0]
11
+
12
+ ### Added
13
+
14
+ - Add `decodeMnemonic` and `decodeMnemonicWords` ([#612](https://github.com/MetaMask/accounts/pull/612))
15
+
10
16
  ## [3.0.0]
11
17
 
12
18
  ### Added
@@ -114,7 +120,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
114
120
 
115
121
  - Initial release, extracted from `@metamask/keyring-api` ([#478](https://github.com/MetaMask/accounts/pull/478), [#482](https://github.com/MetaMask/accounts/pull/482))
116
122
 
117
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@3.0.0...HEAD
123
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@3.1.0...HEAD
124
+ [3.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@3.0.0...@metamask/keyring-sdk@3.1.0
118
125
  [3.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.3.0...@metamask/keyring-sdk@3.0.0
119
126
  [2.3.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.2.0...@metamask/keyring-sdk@2.3.0
120
127
  [2.2.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.1.1...@metamask/keyring-sdk@2.2.0
package/dist/mnemonic.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeMnemonic = exports.encodeMnemonicWords = void 0;
3
+ exports.decodeMnemonic = exports.decodeMnemonicWords = exports.encodeMnemonic = exports.encodeMnemonicWords = void 0;
4
4
  const english_1 = require("@metamask/scure-bip39/dist/wordlists/english.js");
5
5
  /**
6
6
  * Encodes a mnemonic as a string of words.
@@ -27,4 +27,39 @@ function encodeMnemonic(mnemonicIndicesBytes) {
27
27
  return Array.from(new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)));
28
28
  }
29
29
  exports.encodeMnemonic = encodeMnemonic;
30
+ /**
31
+ * Decodes a string of mnemonic words as an array of bytes (16-bit unsigned
32
+ * integers) representing the indices of the words in the mnemonic.
33
+ *
34
+ * @param mnemonic - A string representing the mnemonic.
35
+ * @returns An array of bytes representing the indices of the words in the mnemonic.
36
+ * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
37
+ */
38
+ function decodeMnemonicWords(mnemonic) {
39
+ if (mnemonic === '') {
40
+ return new Uint8Array();
41
+ }
42
+ const mnemonicIndices = mnemonic.split(' ').map((word) => {
43
+ const index = english_1.wordlist.indexOf(word);
44
+ if (index === -1) {
45
+ throw new Error(`Invalid mnemonic word: "${word}"`);
46
+ }
47
+ return index;
48
+ });
49
+ return new Uint8Array(new Uint16Array(mnemonicIndices).buffer);
50
+ }
51
+ exports.decodeMnemonicWords = decodeMnemonicWords;
52
+ /**
53
+ * Decodes an array of bytes (UTF-8) representing a mnemonic as an array of
54
+ * bytes (16-bit unsigned integers) representing the indices of the words in
55
+ * the mnemonic.
56
+ *
57
+ * @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.
58
+ * @returns An array of bytes representing the indices of the words in the mnemonic.
59
+ * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
60
+ */
61
+ function decodeMnemonic(mnemonicBytes) {
62
+ return decodeMnemonicWords(new TextDecoder().decode(mnemonicBytes));
63
+ }
64
+ exports.decodeMnemonic = decodeMnemonic;
30
65
  //# sourceMappingURL=mnemonic.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mnemonic.cjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":";;;AAAA,6EAAwE;AAExE;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,oBAAgC;IAClE,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI;IAChC,0EAA0E;IAC1E,iEAAiE;IACjE,oBAAoB;IACpB,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAC7D,CAAC;IACF,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3D,CAAC;AARD,kDAQC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,oBAAgC;IAC7D,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CACpE,CAAC;AACJ,CAAC;AAJD,wCAIC","sourcesContent":["import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\n\n/**\n * Encodes a mnemonic as a string of words.\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns A string representing the mnemonic.\n */\nexport function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): string {\n const mnemonicIndices = Array.from(\n // Create a new `Uint8Array` to ensure we have a proper view on the buffer\n // without having to worry about `byteOffset` and `byteLength` of\n // the inner buffer.\n new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer),\n );\n return mnemonicIndices.map((i) => wordlist[i]).join(' ');\n}\n\n/**\n * Encodes a mnemonic as an array of bytes (UTF-8).\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns An array of bytes (UTF-8) representing the mnemonic.\n */\nexport function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[] {\n return Array.from(\n new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)),\n );\n}\n"]}
1
+ {"version":3,"file":"mnemonic.cjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":";;;AAAA,6EAAwE;AAExE;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,oBAAgC;IAClE,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI;IAChC,0EAA0E;IAC1E,iEAAiE;IACjE,oBAAoB;IACpB,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAC7D,CAAC;IACF,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3D,CAAC;AARD,kDAQC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,oBAAgC;IAC7D,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CACpE,CAAC;AACJ,CAAC;AAJD,wCAIC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,IAAI,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,MAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACvD,MAAM,KAAK,GAAG,kBAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,GAAG,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,UAAU,CAAC,IAAI,WAAW,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AACjE,CAAC;AAdD,kDAcC;AAED;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAAC,aAAyB;IACtD,OAAO,mBAAmB,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AACtE,CAAC;AAFD,wCAEC","sourcesContent":["import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\n\n/**\n * Encodes a mnemonic as a string of words.\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns A string representing the mnemonic.\n */\nexport function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): string {\n const mnemonicIndices = Array.from(\n // Create a new `Uint8Array` to ensure we have a proper view on the buffer\n // without having to worry about `byteOffset` and `byteLength` of\n // the inner buffer.\n new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer),\n );\n return mnemonicIndices.map((i) => wordlist[i]).join(' ');\n}\n\n/**\n * Encodes a mnemonic as an array of bytes (UTF-8).\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns An array of bytes (UTF-8) representing the mnemonic.\n */\nexport function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[] {\n return Array.from(\n new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)),\n );\n}\n\n/**\n * Decodes a string of mnemonic words as an array of bytes (16-bit unsigned\n * integers) representing the indices of the words in the mnemonic.\n *\n * @param mnemonic - A string representing the mnemonic.\n * @returns An array of bytes representing the indices of the words in the mnemonic.\n * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.\n */\nexport function decodeMnemonicWords(mnemonic: string): Uint8Array {\n if (mnemonic === '') {\n return new Uint8Array();\n }\n\n const mnemonicIndices = mnemonic.split(' ').map((word) => {\n const index = wordlist.indexOf(word);\n if (index === -1) {\n throw new Error(`Invalid mnemonic word: \"${word}\"`);\n }\n return index;\n });\n\n return new Uint8Array(new Uint16Array(mnemonicIndices).buffer);\n}\n\n/**\n * Decodes an array of bytes (UTF-8) representing a mnemonic as an array of\n * bytes (16-bit unsigned integers) representing the indices of the words in\n * the mnemonic.\n *\n * @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.\n * @returns An array of bytes representing the indices of the words in the mnemonic.\n * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.\n */\nexport function decodeMnemonic(mnemonicBytes: Uint8Array): Uint8Array {\n return decodeMnemonicWords(new TextDecoder().decode(mnemonicBytes));\n}\n"]}
@@ -12,4 +12,23 @@ export declare function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): s
12
12
  * @returns An array of bytes (UTF-8) representing the mnemonic.
13
13
  */
14
14
  export declare function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[];
15
+ /**
16
+ * Decodes a string of mnemonic words as an array of bytes (16-bit unsigned
17
+ * integers) representing the indices of the words in the mnemonic.
18
+ *
19
+ * @param mnemonic - A string representing the mnemonic.
20
+ * @returns An array of bytes representing the indices of the words in the mnemonic.
21
+ * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
22
+ */
23
+ export declare function decodeMnemonicWords(mnemonic: string): Uint8Array;
24
+ /**
25
+ * Decodes an array of bytes (UTF-8) representing a mnemonic as an array of
26
+ * bytes (16-bit unsigned integers) representing the indices of the words in
27
+ * the mnemonic.
28
+ *
29
+ * @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.
30
+ * @returns An array of bytes representing the indices of the words in the mnemonic.
31
+ * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
32
+ */
33
+ export declare function decodeMnemonic(mnemonicBytes: Uint8Array): Uint8Array;
15
34
  //# sourceMappingURL=mnemonic.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mnemonic.d.cts","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,CAQ5E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,EAAE,CAIzE"}
1
+ {"version":3,"file":"mnemonic.d.cts","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,CAQ5E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,EAAE,CAIzE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAchE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,UAAU,GAAG,UAAU,CAEpE"}
@@ -12,4 +12,23 @@ export declare function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): s
12
12
  * @returns An array of bytes (UTF-8) representing the mnemonic.
13
13
  */
14
14
  export declare function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[];
15
+ /**
16
+ * Decodes a string of mnemonic words as an array of bytes (16-bit unsigned
17
+ * integers) representing the indices of the words in the mnemonic.
18
+ *
19
+ * @param mnemonic - A string representing the mnemonic.
20
+ * @returns An array of bytes representing the indices of the words in the mnemonic.
21
+ * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
22
+ */
23
+ export declare function decodeMnemonicWords(mnemonic: string): Uint8Array;
24
+ /**
25
+ * Decodes an array of bytes (UTF-8) representing a mnemonic as an array of
26
+ * bytes (16-bit unsigned integers) representing the indices of the words in
27
+ * the mnemonic.
28
+ *
29
+ * @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.
30
+ * @returns An array of bytes representing the indices of the words in the mnemonic.
31
+ * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
32
+ */
33
+ export declare function decodeMnemonic(mnemonicBytes: Uint8Array): Uint8Array;
15
34
  //# sourceMappingURL=mnemonic.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mnemonic.d.mts","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,CAQ5E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,EAAE,CAIzE"}
1
+ {"version":3,"file":"mnemonic.d.mts","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,CAQ5E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,oBAAoB,EAAE,UAAU,GAAG,MAAM,EAAE,CAIzE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAchE;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,UAAU,GAAG,UAAU,CAEpE"}
package/dist/mnemonic.mjs CHANGED
@@ -22,4 +22,37 @@ export function encodeMnemonicWords(mnemonicIndicesBytes) {
22
22
  export function encodeMnemonic(mnemonicIndicesBytes) {
23
23
  return Array.from(new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)));
24
24
  }
25
+ /**
26
+ * Decodes a string of mnemonic words as an array of bytes (16-bit unsigned
27
+ * integers) representing the indices of the words in the mnemonic.
28
+ *
29
+ * @param mnemonic - A string representing the mnemonic.
30
+ * @returns An array of bytes representing the indices of the words in the mnemonic.
31
+ * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
32
+ */
33
+ export function decodeMnemonicWords(mnemonic) {
34
+ if (mnemonic === '') {
35
+ return new Uint8Array();
36
+ }
37
+ const mnemonicIndices = mnemonic.split(' ').map((word) => {
38
+ const index = wordlist.indexOf(word);
39
+ if (index === -1) {
40
+ throw new Error(`Invalid mnemonic word: "${word}"`);
41
+ }
42
+ return index;
43
+ });
44
+ return new Uint8Array(new Uint16Array(mnemonicIndices).buffer);
45
+ }
46
+ /**
47
+ * Decodes an array of bytes (UTF-8) representing a mnemonic as an array of
48
+ * bytes (16-bit unsigned integers) representing the indices of the words in
49
+ * the mnemonic.
50
+ *
51
+ * @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.
52
+ * @returns An array of bytes representing the indices of the words in the mnemonic.
53
+ * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.
54
+ */
55
+ export function decodeMnemonic(mnemonicBytes) {
56
+ return decodeMnemonicWords(new TextDecoder().decode(mnemonicBytes));
57
+ }
25
58
  //# sourceMappingURL=mnemonic.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mnemonic.mjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAqD;AAExE;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,oBAAgC;IAClE,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI;IAChC,0EAA0E;IAC1E,iEAAiE;IACjE,oBAAoB;IACpB,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAC7D,CAAC;IACF,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,oBAAgC;IAC7D,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CACpE,CAAC;AACJ,CAAC","sourcesContent":["import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\n\n/**\n * Encodes a mnemonic as a string of words.\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns A string representing the mnemonic.\n */\nexport function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): string {\n const mnemonicIndices = Array.from(\n // Create a new `Uint8Array` to ensure we have a proper view on the buffer\n // without having to worry about `byteOffset` and `byteLength` of\n // the inner buffer.\n new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer),\n );\n return mnemonicIndices.map((i) => wordlist[i]).join(' ');\n}\n\n/**\n * Encodes a mnemonic as an array of bytes (UTF-8).\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns An array of bytes (UTF-8) representing the mnemonic.\n */\nexport function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[] {\n return Array.from(\n new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)),\n );\n}\n"]}
1
+ {"version":3,"file":"mnemonic.mjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,wDAAqD;AAExE;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,oBAAgC;IAClE,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI;IAChC,0EAA0E;IAC1E,iEAAiE;IACjE,oBAAoB;IACpB,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAC7D,CAAC;IACF,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,oBAAgC;IAC7D,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,CACpE,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,IAAI,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,MAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,GAAG,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,UAAU,CAAC,IAAI,WAAW,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,aAAyB;IACtD,OAAO,mBAAmB,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\n\n/**\n * Encodes a mnemonic as a string of words.\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns A string representing the mnemonic.\n */\nexport function encodeMnemonicWords(mnemonicIndicesBytes: Uint8Array): string {\n const mnemonicIndices = Array.from(\n // Create a new `Uint8Array` to ensure we have a proper view on the buffer\n // without having to worry about `byteOffset` and `byteLength` of\n // the inner buffer.\n new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer),\n );\n return mnemonicIndices.map((i) => wordlist[i]).join(' ');\n}\n\n/**\n * Encodes a mnemonic as an array of bytes (UTF-8).\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns An array of bytes (UTF-8) representing the mnemonic.\n */\nexport function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[] {\n return Array.from(\n new TextEncoder().encode(encodeMnemonicWords(mnemonicIndicesBytes)),\n );\n}\n\n/**\n * Decodes a string of mnemonic words as an array of bytes (16-bit unsigned\n * integers) representing the indices of the words in the mnemonic.\n *\n * @param mnemonic - A string representing the mnemonic.\n * @returns An array of bytes representing the indices of the words in the mnemonic.\n * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.\n */\nexport function decodeMnemonicWords(mnemonic: string): Uint8Array {\n if (mnemonic === '') {\n return new Uint8Array();\n }\n\n const mnemonicIndices = mnemonic.split(' ').map((word) => {\n const index = wordlist.indexOf(word);\n if (index === -1) {\n throw new Error(`Invalid mnemonic word: \"${word}\"`);\n }\n return index;\n });\n\n return new Uint8Array(new Uint16Array(mnemonicIndices).buffer);\n}\n\n/**\n * Decodes an array of bytes (UTF-8) representing a mnemonic as an array of\n * bytes (16-bit unsigned integers) representing the indices of the words in\n * the mnemonic.\n *\n * @param mnemonicBytes - An array of bytes (UTF-8) representing the mnemonic.\n * @returns An array of bytes representing the indices of the words in the mnemonic.\n * @throws If the mnemonic contains a word that is not in the English BIP-39 wordlist.\n */\nexport function decodeMnemonic(mnemonicBytes: Uint8Array): Uint8Array {\n return decodeMnemonicWords(new TextDecoder().decode(mnemonicBytes));\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "MetaMask Keyring SDK",
5
5
  "keywords": [
6
6
  "keyring",