|
| 1 | +import * as assert from 'assert'; |
| 2 | +import 'should'; |
| 3 | +import { getDerivationPath } from '@bitgo/sdk-lib-mpc'; |
| 4 | + |
| 5 | +function getAddressVerificationModule() { |
| 6 | + return require('../../../../../src/bitgo/utils/tss/addressVerification'); |
| 7 | +} |
| 8 | + |
| 9 | +const getExtractCommonKeychain = () => getAddressVerificationModule().extractCommonKeychain; |
| 10 | + |
| 11 | +describe('TSS Address Verification - Derivation Path with Prefix', function () { |
| 12 | + const commonKeychain = |
| 13 | + '8ea32ecacfc83effbd2e2790ee44fa7c59b4d86c29a12f09fb613d8195f93f4e21875cad3b98adada40c040c54c3569467df41a020881a6184096378701862bd'; |
| 14 | + |
| 15 | + describe('extractCommonKeychain', function () { |
| 16 | + it('should extract commonKeychain from keychains array', function () { |
| 17 | + const extractCommonKeychain = getExtractCommonKeychain(); |
| 18 | + const keychains = [{ commonKeychain }, { commonKeychain }, { commonKeychain }]; |
| 19 | + |
| 20 | + const result = extractCommonKeychain(keychains); |
| 21 | + result.should.equal(commonKeychain); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should throw error if keychains are missing', function () { |
| 25 | + const extractCommonKeychain = getExtractCommonKeychain(); |
| 26 | + assert.throws(() => extractCommonKeychain([]), /missing required param keychains/); |
| 27 | + assert.throws(() => extractCommonKeychain(undefined as any), /missing required param keychains/); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should throw error if commonKeychain is missing', function () { |
| 31 | + const extractCommonKeychain = getExtractCommonKeychain(); |
| 32 | + const keychains = [{ id: '1' }]; |
| 33 | + assert.throws(() => extractCommonKeychain(keychains as any), /missing required param commonKeychain/); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should throw error if keychains have mismatched commonKeychains', function () { |
| 37 | + const extractCommonKeychain = getExtractCommonKeychain(); |
| 38 | + const keychains = [{ commonKeychain }, { commonKeychain: 'different-keychain' }]; |
| 39 | + assert.throws(() => extractCommonKeychain(keychains), /all keychains must have the same commonKeychain/); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('Derivation Path Format Validation', function () { |
| 44 | + it('should produce correct derivation path format', function () { |
| 45 | + const testSeeds = ['seed1', 'seed-2', '12345', 'test_seed_123']; |
| 46 | + |
| 47 | + testSeeds.forEach((seed) => { |
| 48 | + const path = getDerivationPath(seed); |
| 49 | + |
| 50 | + // Expected format: "m/999999/{part1}/{part2}" |
| 51 | + path.should.match(/^m\/999999\/\d+\/\d+$/); |
| 52 | + |
| 53 | + path.should.startWith('m/'); |
| 54 | + |
| 55 | + // Should have exactly 3 parts |
| 56 | + const parts = path.split('/'); |
| 57 | + parts.length.should.equal(4); |
| 58 | + parts[0].should.equal('m'); |
| 59 | + parts[1].should.equal('999999'); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments