@meshsdk/wallet 1.6.0-alpha.11
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/README.md +5 -0
- package/jest.config.js +5 -0
- package/package.json +36 -0
- package/src/app/index.ts +239 -0
- package/src/browser/index.ts +440 -0
- package/src/embedded/index.ts +258 -0
- package/src/index.ts +4 -0
- package/src/mesh/index.ts +413 -0
- package/src/types/index.ts +39 -0
- package/test/app.test.ts +98 -0
- package/test/browser.test.ts +21 -0
- package/test/embedded.test.ts +137 -0
- package/test/mesh.test.ts +95 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { checkSignature } from "@meshsdk/core-cst";
|
|
2
|
+
import { EmbeddedWallet } from "@meshsdk/wallet";
|
|
3
|
+
|
|
4
|
+
describe("EmbeddedWallet mnemonic", () => {
|
|
5
|
+
const wallet = new EmbeddedWallet({
|
|
6
|
+
networkId: 0,
|
|
7
|
+
key: {
|
|
8
|
+
type: "mnemonic",
|
|
9
|
+
words: "solution,".repeat(24).split(",").slice(0, 24),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("generate mnemonic", () => {
|
|
14
|
+
const mnemonic = EmbeddedWallet.generateMnemonic();
|
|
15
|
+
expect(mnemonic.length).toEqual(24);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("correct base address", () => {
|
|
19
|
+
const account = wallet.getAccount(0, 0);
|
|
20
|
+
expect(account.baseAddressBech32).toEqual(
|
|
21
|
+
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9",
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("correct enterprise address", () => {
|
|
26
|
+
const account = wallet.getAccount(0, 0);
|
|
27
|
+
expect(account.enterpriseAddressBech32).toEqual(
|
|
28
|
+
"addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr",
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("correct reward address", () => {
|
|
33
|
+
const account = wallet.getAccount(0, 0);
|
|
34
|
+
expect(account.rewardAddressBech32).toEqual(
|
|
35
|
+
"stake_test1uzw5mnt7g4xjgdqkfa80hrk7kdvds6sa4k0vvgjvlj7w8eskffj2n",
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("sign message", () => {
|
|
40
|
+
const message = `meshjs's core-cst is pure typescript while core-csl is wasm rust.`;
|
|
41
|
+
const signature = wallet.signData(
|
|
42
|
+
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9",
|
|
43
|
+
message,
|
|
44
|
+
0,
|
|
45
|
+
0,
|
|
46
|
+
);
|
|
47
|
+
const result = checkSignature(message, signature);
|
|
48
|
+
|
|
49
|
+
expect(signature.key).toEqual(
|
|
50
|
+
"c32dfdb461dd016e8fdd9b6d424a77439eab8f8c644a804b013b6cefa2454f95",
|
|
51
|
+
);
|
|
52
|
+
expect(signature.signature).toEqual(
|
|
53
|
+
"2808fc47212c2fe2151ccb4209cc7c5cf44b5ec6a80e21232a3f004697bd795b5610880184d8466761820bcb38401cc1e16945b1c1944037ce92a0929e729a0f",
|
|
54
|
+
);
|
|
55
|
+
expect(result).toEqual(true);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("EmbeddedWallet privateKey", () => {
|
|
60
|
+
const walletMnemonic = new EmbeddedWallet({
|
|
61
|
+
networkId: 0,
|
|
62
|
+
key: {
|
|
63
|
+
type: "mnemonic",
|
|
64
|
+
words: [
|
|
65
|
+
"ramp",
|
|
66
|
+
"over",
|
|
67
|
+
"popular",
|
|
68
|
+
"angry",
|
|
69
|
+
"flock",
|
|
70
|
+
"idle",
|
|
71
|
+
"silent",
|
|
72
|
+
"stove",
|
|
73
|
+
"very",
|
|
74
|
+
"hover",
|
|
75
|
+
"hip",
|
|
76
|
+
"juice",
|
|
77
|
+
"dentist",
|
|
78
|
+
"mask",
|
|
79
|
+
"radar",
|
|
80
|
+
"example",
|
|
81
|
+
"layer",
|
|
82
|
+
"tongue",
|
|
83
|
+
"shift",
|
|
84
|
+
"cement",
|
|
85
|
+
"margin",
|
|
86
|
+
"since",
|
|
87
|
+
"floor",
|
|
88
|
+
"clinic",
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const walletRoot = new EmbeddedWallet({
|
|
94
|
+
networkId: 0,
|
|
95
|
+
key: {
|
|
96
|
+
type: "root",
|
|
97
|
+
bech32:
|
|
98
|
+
"xprv1tzdu7xzqjc0j8jzlsjwdvchczkxu4qjyhkxewtcuu7zt3amd44x6emkcrzks8gthdwyfavq98ayp06434yda6xudfd5zltd4tjxhdu37qumdlvcx8f05pp5n45j6nwqztx2ra0jm636xqluwxw47vlrlzqp7a0a9",
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("correct addresses", () => {
|
|
103
|
+
const accountMnemonic = walletMnemonic.getAccount(0, 0);
|
|
104
|
+
expect(accountMnemonic.enterpriseAddressBech32).toEqual(
|
|
105
|
+
"addr_test1vz0vlyux43d7c4su8uzkkqvm6vug28t3zvnycxjnuvnxa0c5gr4p9",
|
|
106
|
+
);
|
|
107
|
+
const accountRoot = walletRoot.getAccount(0, 0);
|
|
108
|
+
expect(accountRoot.enterpriseAddressBech32).toEqual(
|
|
109
|
+
"addr_test1vz0vlyux43d7c4su8uzkkqvm6vug28t3zvnycxjnuvnxa0c5gr4p9",
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("EmbeddedWallet signingKeys", () => {
|
|
115
|
+
const wallet = new EmbeddedWallet({
|
|
116
|
+
networkId: 0,
|
|
117
|
+
key: {
|
|
118
|
+
type: "cli",
|
|
119
|
+
payment:
|
|
120
|
+
"f083e5878c6f980c53d30b9cc2baadd780307b08acec9e0792892e013bbe9241",
|
|
121
|
+
stake: "b810d6398db44f380a9ab279f63950c4b95432f44fafb5a6f026afe23bbe9241",
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("correct addresses", () => {
|
|
126
|
+
const account = wallet.getAccount(0, 0);
|
|
127
|
+
expect(account.baseAddressBech32).toEqual(
|
|
128
|
+
"addr_test1qqdy60gf798xrl20wwvapvsxj3kr8yz8ac6zfmgwg6c5g9p3x07mt562mneg8jxgj03p2uvmhyfyvktjn259mws8e6wq3cdn8p",
|
|
129
|
+
);
|
|
130
|
+
expect(account.enterpriseAddressBech32).toEqual(
|
|
131
|
+
"addr_test1vqdy60gf798xrl20wwvapvsxj3kr8yz8ac6zfmgwg6c5g9qh602xh",
|
|
132
|
+
);
|
|
133
|
+
expect(account.rewardAddressBech32).toEqual(
|
|
134
|
+
"stake_test1uqcn8ld46d9deu5reryf8cs4wxdmjyjxt9ef42zahgrua8qctnd74",
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { MeshWallet } from "@meshsdk/wallet";
|
|
2
|
+
|
|
3
|
+
describe("MeshWallet", () => {
|
|
4
|
+
const wallet = new MeshWallet({
|
|
5
|
+
networkId: 0,
|
|
6
|
+
key: {
|
|
7
|
+
type: "mnemonic",
|
|
8
|
+
words: "solution,".repeat(24).split(",").slice(0, 24),
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("private keys", () => {
|
|
13
|
+
const wallet = new MeshWallet({
|
|
14
|
+
networkId: 0,
|
|
15
|
+
key: {
|
|
16
|
+
type: "root",
|
|
17
|
+
bech32:
|
|
18
|
+
"xprv1cqa46gk29plgkg98upclnjv5t425fcpl4rgf9mq2txdxuga7jfq5shk7np6l55nj00sl3m4syzna3uwgrwppdm0azgy9d8zahyf32s62klfyhe0ayyxkc7x92nv4s77fa0v25tufk9tnv7x6dgexe9kdz5gpeqgu",
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
expect(wallet.getChangeAddress()).toEqual(
|
|
22
|
+
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9",
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("cli keys", () => {
|
|
27
|
+
const wallet = new MeshWallet({
|
|
28
|
+
networkId: 0,
|
|
29
|
+
key: {
|
|
30
|
+
type: "cli",
|
|
31
|
+
payment:
|
|
32
|
+
"5820f083e5878c6f980c53d30b9cc2baadd780307b08acec9e0792892e013bbe9241",
|
|
33
|
+
stake:
|
|
34
|
+
"5820b810d6398db44f380a9ab279f63950c4b95432f44fafb5a6f026afe23bbe9241",
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
expect(wallet.getChangeAddress()).toEqual(
|
|
38
|
+
"addr_test1qqdy60gf798xrl20wwvapvsxj3kr8yz8ac6zfmgwg6c5g9p3x07mt562mneg8jxgj03p2uvmhyfyvktjn259mws8e6wq3cdn8p",
|
|
39
|
+
);
|
|
40
|
+
expect(wallet.getRewardAddresses()[0]).toEqual(
|
|
41
|
+
"stake_test1uqcn8ld46d9deu5reryf8cs4wxdmjyjxt9ef42zahgrua8qctnd74",
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("getChangeAddress", () => {
|
|
46
|
+
const changeAddress = wallet.getChangeAddress();
|
|
47
|
+
expect(changeAddress).toEqual(
|
|
48
|
+
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9",
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("getNetworkId", () => {
|
|
53
|
+
const networkId = wallet.getNetworkId();
|
|
54
|
+
expect(networkId).toEqual(0);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("getRewardAddresses", () => {
|
|
58
|
+
const addresses = wallet.getRewardAddresses();
|
|
59
|
+
expect(addresses).toEqual([
|
|
60
|
+
"stake_test1uzw5mnt7g4xjgdqkfa80hrk7kdvds6sa4k0vvgjvlj7w8eskffj2n",
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("getUnusedAddresses", () => {
|
|
65
|
+
const addresses = wallet.getUnusedAddresses();
|
|
66
|
+
expect(addresses).toEqual([
|
|
67
|
+
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9",
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("getUsedAddresses", () => {
|
|
72
|
+
const addresses = wallet.getUsedAddresses();
|
|
73
|
+
expect(addresses).toEqual([
|
|
74
|
+
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9",
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("getUsedAddress", () => {
|
|
79
|
+
const address = wallet.getUsedAddress();
|
|
80
|
+
expect(address.toBech32()).toEqual(
|
|
81
|
+
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9",
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("brew", () => {
|
|
86
|
+
const mnemonic = MeshWallet.brew();
|
|
87
|
+
expect(mnemonic.length).toEqual(24);
|
|
88
|
+
|
|
89
|
+
const privatekey = MeshWallet.brew(true);
|
|
90
|
+
expect(privatekey.length).toEqual(165);
|
|
91
|
+
|
|
92
|
+
if (typeof privatekey === "string")
|
|
93
|
+
expect(privatekey.substring(0, 5)).toEqual("xprv1");
|
|
94
|
+
});
|
|
95
|
+
});
|