Skip to content

Commit def5d9a

Browse files
authored
Merge pull request input-output-hk#40 from input-output-hk/fix-issue-39
fix bug regarding `Wallet.fromSeed` where the seed length was not tested properly
2 parents ce00d2e + 5d4528d commit def5d9a

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

js/HdWallet.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import RustModule from './RustModule';
33
import { newArray, newArray0, copyArray } from './utils/arrays';
44
import { apply } from './utils/functions';
55

6-
const SEED_SIZE = 32;
7-
const XPRV_SIZE = 96;
8-
const XPUB_SIZE = 64;
9-
const SIGNATURE_SIZE = 64;
6+
export const SEED_SIZE = 32;
7+
export const XPRV_SIZE = 96;
8+
export const XPUB_SIZE = 64;
9+
export const SIGNATURE_SIZE = 64;
1010

1111

1212
/**
@@ -167,5 +167,9 @@ export default {
167167
derivePublic: apply(derivePublic, RustModule),
168168
sign: apply(sign, RustModule),
169169
publicKeyToAddress: apply(publicKeyToAddress, RustModule),
170-
addressGetPayload: apply(addressGetPayload, RustModule)
170+
addressGetPayload: apply(addressGetPayload, RustModule),
171+
SEED_SIZE: SEED_SIZE,
172+
XPRV_SIZE: XPRV_SIZE,
173+
XPUB_SIZE: XPUB_SIZE,
174+
SIGNATURE_SIZE: SIGNATURE_SIZE,
171175
};

js/tests/from-seed.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const expect = require('chai').expect;
2+
const CardanoCrypto = require('../../dist/index.js');
3+
4+
const SEED = Array(32).fill(0);
5+
6+
describe('Wallet FromSeed', async function() {
7+
let xprv = null;
8+
let wallet = null;
9+
let account = null;
10+
11+
before(async () => {
12+
await CardanoCrypto.loadRustModule()
13+
});
14+
15+
it("check seed size", function() {
16+
expect(SEED.length).equals(CardanoCrypto.HdWallet.SEED_SIZE);
17+
});
18+
it("create a wallet", function() {
19+
const result = CardanoCrypto.Wallet.fromSeed(SEED);
20+
console.log(result);
21+
expect(result.failed).equals(false);
22+
wallet = result.result;
23+
});
24+
});

0 commit comments

Comments
 (0)