|
| 1 | +import * as assert from 'assert'; |
| 2 | +import { derivePassword } from '../../src'; |
| 3 | + |
| 4 | +describe('derivePassword', function () { |
| 5 | + it('throws if prfResult is undefined', function () { |
| 6 | + assert.throws(() => derivePassword(undefined), /Failed to derive password/); |
| 7 | + }); |
| 8 | + |
| 9 | + it('produces a known hex password for a given PRF output', function () { |
| 10 | + // Known 32-byte PRF result → expected hex-encoded wallet passphrase |
| 11 | + const prfBytes = new Uint8Array([ |
| 12 | + 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0xba, 0xbe, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, |
| 13 | + 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
| 14 | + ]); |
| 15 | + assert.strictEqual( |
| 16 | + derivePassword(prfBytes.buffer), |
| 17 | + 'deadbeefcafebabe0123456789abcdeffedcba98765432100011223344556677' |
| 18 | + ); |
| 19 | + }); |
| 20 | + |
| 21 | + it('converts an ArrayBuffer of zeros to a hex string of zeros', function () { |
| 22 | + assert.strictEqual(derivePassword(new ArrayBuffer(4)), '00000000'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('returns a lowercase hex string', function () { |
| 26 | + const input = new Uint8Array([0xab, 0xcd]).buffer; |
| 27 | + const result = derivePassword(input); |
| 28 | + assert.strictEqual(result, result.toLowerCase()); |
| 29 | + }); |
| 30 | + |
| 31 | + it('returns a string of length 2x the input byte length', function () { |
| 32 | + assert.strictEqual(derivePassword(new ArrayBuffer(32)).length, 64); |
| 33 | + }); |
| 34 | + |
| 35 | + it('is deterministic — same inputs produce same output', function () { |
| 36 | + const input = new Uint8Array([1, 2, 3, 4, 5]).buffer; |
| 37 | + assert.strictEqual(derivePassword(input), derivePassword(input)); |
| 38 | + }); |
| 39 | +}); |
0 commit comments