mainnet-js 3.1.2 → 3.1.5
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/dist/index.html +1 -1
- package/dist/{mainnet-3.1.2.js → mainnet-3.1.5.js} +5 -5
- package/dist/module/cache/walletCache.d.ts +2 -1
- package/dist/module/cache/walletCache.d.ts.map +1 -1
- package/dist/module/cache/walletCache.js +1 -1
- package/dist/module/cache/walletCache.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +4 -4
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +1 -1
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/wallet/Base.d.ts +1 -1
- package/dist/module/wallet/Base.d.ts.map +1 -1
- package/dist/module/wallet/Base.js +1 -0
- package/dist/module/wallet/Base.js.map +1 -1
- package/dist/module/wallet/HDWallet.d.ts.map +1 -1
- package/dist/module/wallet/HDWallet.js +2 -2
- package/dist/module/wallet/HDWallet.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +6 -1
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/cache/walletCache.ts +1 -1
- package/src/transaction/Wif.ts +5 -5
- package/src/wallet/Base.ts +2 -1
- package/src/wallet/HDWallet.ts +2 -2
- package/src/wallet/WalletCache.test.ts +45 -0
- package/src/wallet/Wif.test.ts +2 -0
- package/src/wallet/Wif.ts +8 -1
package/src/wallet/HDWallet.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
sha256,
|
|
17
17
|
utf8ToBin,
|
|
18
18
|
} from "@bitauth/libauth";
|
|
19
|
-
import {
|
|
19
|
+
import { PersistentWalletCache, WalletCacheI } from "../cache/index.js";
|
|
20
20
|
import { Config } from "../config.js";
|
|
21
21
|
import { NetworkType, prefixFromNetworkMap, UnitEnum } from "../enum.js";
|
|
22
22
|
import { getHistory } from "../history/getHistory.js";
|
|
@@ -240,7 +240,7 @@ export class HDWallet extends BaseWallet {
|
|
|
240
240
|
)
|
|
241
241
|
);
|
|
242
242
|
// @ts-ignore
|
|
243
|
-
this.walletCache = new
|
|
243
|
+
this.walletCache = new PersistentWalletCache(
|
|
244
244
|
this.walletId,
|
|
245
245
|
this.xPrivNode ?? this.xPubNode,
|
|
246
246
|
this.networkPrefix
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { RegTestWallet, RegTestWifWallet } from "./Wif";
|
|
2
|
+
import { RegTestWatchWallet } from "./Watch";
|
|
3
|
+
import { RegTestHDWallet } from "./HDWallet";
|
|
4
|
+
|
|
5
|
+
describe("Wallet cache initialization", () => {
|
|
6
|
+
test("Seed wallet should have walletCache with at least one entry", async () => {
|
|
7
|
+
const wallet = await RegTestWallet.newRandom();
|
|
8
|
+
expect(wallet.walletCache).toBeDefined();
|
|
9
|
+
expect(wallet.walletCache!.get(wallet.cashaddr)).toBeDefined();
|
|
10
|
+
expect(wallet.walletCache!.get(wallet.cashaddr)!.privateKey).toBeDefined();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("Wif wallet should have walletCache with at least one entry", async () => {
|
|
14
|
+
const wallet = await RegTestWifWallet.newRandom();
|
|
15
|
+
expect(wallet.walletCache).toBeDefined();
|
|
16
|
+
expect(wallet.walletCache!.get(wallet.cashaddr)).toBeDefined();
|
|
17
|
+
expect(wallet.walletCache!.get(wallet.cashaddr)!.privateKey).toBeDefined();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("Wif wallet from ID should have walletCache with at least one entry", async () => {
|
|
21
|
+
const wallet = await RegTestWallet.fromId(
|
|
22
|
+
"wif:regtest:cNfsPtqN2bMRS7vH5qd8tR8GMvgXyL5BjnGAKgZ8DYEiCrCCQcP6"
|
|
23
|
+
);
|
|
24
|
+
expect(wallet.walletCache).toBeDefined();
|
|
25
|
+
expect(wallet.walletCache!.get(wallet.cashaddr)).toBeDefined();
|
|
26
|
+
expect(wallet.walletCache!.get(wallet.cashaddr)!.privateKey).toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("HD wallet should have walletCache with at least one entry", async () => {
|
|
30
|
+
const wallet = await RegTestHDWallet.newRandom();
|
|
31
|
+
expect(wallet.walletCache).toBeDefined();
|
|
32
|
+
const depositAddr = wallet.getDepositAddress();
|
|
33
|
+
expect(wallet.walletCache!.get(depositAddr)).toBeDefined();
|
|
34
|
+
expect(wallet.walletCache!.get(depositAddr)!.privateKey).toBeDefined();
|
|
35
|
+
await wallet.stop();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("Watch wallet should have empty walletCache", async () => {
|
|
39
|
+
const wallet = await RegTestWatchWallet.watchOnly(
|
|
40
|
+
"bchreg:qpttdv3qg2usm4nm7talhxhl05mlhms3ys43u76rn0"
|
|
41
|
+
);
|
|
42
|
+
expect(wallet.walletCache).toBeDefined();
|
|
43
|
+
expect(wallet.walletCache!.get(wallet.cashaddr)).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
});
|
package/src/wallet/Wif.test.ts
CHANGED
package/src/wallet/Wif.ts
CHANGED
|
@@ -215,13 +215,20 @@ export class Wallet extends WatchWallet {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
// rest cases are for watch wallets
|
|
218
|
-
|
|
218
|
+
await super.initialize({
|
|
219
219
|
name,
|
|
220
220
|
publicKey,
|
|
221
221
|
publicKeyCompressed,
|
|
222
222
|
publicKeyHash,
|
|
223
223
|
address,
|
|
224
224
|
});
|
|
225
|
+
|
|
226
|
+
if (this.privateKey) {
|
|
227
|
+
// @ts-ignore
|
|
228
|
+
this.walletCache = new Map<string, { privateKey: Uint8Array }>().set(this.cashaddr, { privateKey: this.privateKey });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return this;
|
|
225
232
|
}
|
|
226
233
|
//#endregion Constructors and Statics
|
|
227
234
|
|