@bsv/sdk 2.1.3 → 2.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -237,23 +237,23 @@
237
237
  },
238
238
  "homepage": "https://github.com/bsv-blockchain/ts-stack/tree/main/packages/sdk#readme",
239
239
  "devDependencies": {
240
- "@eslint/js": "^9.39.1",
241
- "@jest/globals": "^30.3.0",
242
- "@rspack/cli": "^2.0.0",
243
- "@rspack/core": "^1.6.1",
240
+ "@eslint/js": "^10.0.1",
241
+ "@jest/globals": "^30.4.1",
242
+ "@rspack/cli": "^2.0.4",
243
+ "@rspack/core": "^2.0.4",
244
244
  "@types/jest": "^30.0.0",
245
- "@types/node": "^24.10.1",
246
- "eslint": "^9.39.1",
247
- "globals": "^16.5.0",
248
- "jest": "^30.3.0",
249
- "jest-environment-jsdom": "^30.3.0",
250
- "ts-jest": "^29.4.9",
245
+ "@types/node": "^25.9.1",
246
+ "eslint": "^10.4.0",
247
+ "globals": "^17.6.0",
248
+ "jest": "^30.4.2",
249
+ "jest-environment-jsdom": "^30.4.1",
250
+ "ts-jest": "^29.4.11",
251
251
  "ts-loader": "^9.5.4",
252
252
  "ts-standard": "^12.0.2",
253
253
  "ts2md": "^0.2.8",
254
254
  "tsconfig-to-dual-package": "^1.2.0",
255
- "typescript": "^5.9.3",
256
- "typescript-eslint": "^8.46.4"
255
+ "typescript": "^6.0.3",
256
+ "typescript-eslint": "^8.60.0"
257
257
  },
258
258
  "ts-standard": {
259
259
  "project": "tsconfig.eslint.json",
@@ -125,9 +125,22 @@ export default class Mnemonic {
125
125
  * Sets the mnemonic for the instance from a string.
126
126
  * @param {string} mnemonic - The mnemonic phrase as a string.
127
127
  * @returns {this} The Mnemonic instance with the set mnemonic.
128
+ * @throws {Error} If the mnemonic does not pass BIP-39 validation
129
+ * (unknown words, invalid length, or bad checksum).
128
130
  */
129
131
  public fromString (mnemonic: string): this {
130
132
  this.mnemonic = mnemonic
133
+ let valid = false
134
+ try {
135
+ valid = this.check()
136
+ } catch {
137
+ valid = false
138
+ }
139
+ if (!valid) {
140
+ throw new Error(
141
+ 'Mnemonic does not pass the check - was the mnemonic typed incorrectly? Are there extra spaces?'
142
+ )
143
+ }
131
144
  return this
132
145
  }
133
146
 
@@ -49,15 +49,21 @@ describe('Mnemonic', function () {
49
49
  mnemonic = m.mnemonic
50
50
 
51
51
  // mnemonics with extra whitespace do not pass the check
52
- m = new Mnemonic().fromString(mnemonic + ' ')
53
- expect(m.check()).toEqual(false)
52
+ const trailingSpace = mnemonic + ' '
53
+ const trailing = new Mnemonic()
54
+ trailing.mnemonic = trailingSpace
55
+ expect(trailing.check()).toEqual(false)
56
+ expect(() => new Mnemonic().fromString(trailingSpace)).toThrow()
54
57
 
55
58
  // mnemonics with a word replaced do not pass the check
56
59
  const words = mnemonic.split(' ')
57
60
  expect(words[words.length - 1]).not.toEqual('zoo')
58
61
  words[words.length - 1] = 'zoo'
59
- mnemonic = words.join(' ')
60
- expect(new Mnemonic().fromString(mnemonic).check()).toEqual(false)
62
+ const badWord = words.join(' ')
63
+ const replaced = new Mnemonic()
64
+ replaced.mnemonic = badWord
65
+ expect(replaced.check()).toEqual(false)
66
+ expect(() => new Mnemonic().fromString(badWord)).toThrow()
61
67
  })
62
68
 
63
69
  describe('#toBinary', () => {
@@ -132,13 +138,51 @@ describe('Mnemonic', function () {
132
138
  })
133
139
 
134
140
  describe('#fromString', () => {
135
- it('should throw an error in invalid mnemonic', () => {
141
+ it('should throw an error on invalid mnemonic when toSeed is called', () => {
136
142
  expect(() => {
137
143
  new Mnemonic().fromString('invalid mnemonic').toSeed()
138
144
  }).toThrow(
139
145
  'Mnemonic does not pass the check - was the mnemonic typed incorrectly? Are there extra spaces?'
140
146
  )
141
147
  })
148
+
149
+ it('should throw immediately on nonsense input', () => {
150
+ expect(() => {
151
+ Mnemonic.fromString('this is not a real bip39 mnemonic phrase at all')
152
+ }).toThrow(
153
+ 'Mnemonic does not pass the check - was the mnemonic typed incorrectly? Are there extra spaces?'
154
+ )
155
+ })
156
+
157
+ it('should throw on garbage string', () => {
158
+ expect(() => {
159
+ Mnemonic.fromString('asdfghjkl qwertyuiop zxcvbnm')
160
+ }).toThrow()
161
+ })
162
+
163
+ it('should throw on empty string', () => {
164
+ expect(() => {
165
+ Mnemonic.fromString('')
166
+ }).toThrow()
167
+ })
168
+
169
+ it('should throw on valid words but wrong checksum', () => {
170
+ // 12 valid wordlist entries but checksum will not match
171
+ expect(() => {
172
+ Mnemonic.fromString(
173
+ 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon'
174
+ )
175
+ }).toThrow()
176
+ })
177
+
178
+ it('should accept a known-valid BIP-39 phrase', () => {
179
+ const m = Mnemonic.fromString(
180
+ 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
181
+ )
182
+ expect(m.mnemonic).toEqual(
183
+ 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
184
+ )
185
+ })
142
186
  })
143
187
 
144
188
  describe('@isValid', () => {