@polkadot/extension-base 0.42.4-0 → 0.42.4
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/package.json
CHANGED
|
@@ -14,15 +14,14 @@
|
|
|
14
14
|
},
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"type": "module",
|
|
17
|
-
"version": "0.42.4
|
|
17
|
+
"version": "0.42.4",
|
|
18
18
|
"main": "index.js",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.16.5",
|
|
21
21
|
"@polkadot/api": "^7.1.1",
|
|
22
|
-
"@polkadot/extension-chains": "^0.42.4
|
|
23
|
-
"@polkadot/extension-dapp": "^0.42.4
|
|
24
|
-
"@polkadot/extension-inject": "^0.42.4
|
|
25
|
-
"@polkadot/extension-mocks": "^0.42.4-0",
|
|
22
|
+
"@polkadot/extension-chains": "^0.42.4",
|
|
23
|
+
"@polkadot/extension-dapp": "^0.42.4",
|
|
24
|
+
"@polkadot/extension-inject": "^0.42.4",
|
|
26
25
|
"@polkadot/keyring": "^8.2.2",
|
|
27
26
|
"@polkadot/phishing": "^0.6.582",
|
|
28
27
|
"@polkadot/rpc-provider": "^7.1.1",
|
|
@@ -34,6 +33,9 @@
|
|
|
34
33
|
"eventemitter3": "^4.0.7",
|
|
35
34
|
"rxjs": "^7.4.0"
|
|
36
35
|
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@polkadot/extension-mocks": "^0.42.4"
|
|
38
|
+
},
|
|
37
39
|
"exports": {
|
|
38
40
|
".": {
|
|
39
41
|
"types": "./index.d.ts",
|
|
@@ -50,11 +52,6 @@
|
|
|
50
52
|
"require": "./background/handlers/Extension.cjs",
|
|
51
53
|
"default": "./background/handlers/Extension.js"
|
|
52
54
|
},
|
|
53
|
-
"./background/handlers/Extension.test": {
|
|
54
|
-
"types": "./background/handlers/Extension.test.d.ts",
|
|
55
|
-
"require": "./background/handlers/Extension.test.cjs",
|
|
56
|
-
"default": "./background/handlers/Extension.test.js"
|
|
57
|
-
},
|
|
58
55
|
"./background/handlers/helpers": {
|
|
59
56
|
"types": "./background/handlers/helpers.d.ts",
|
|
60
57
|
"require": "./background/handlers/helpers.cjs",
|
package/packageInfo.cjs
CHANGED
package/packageInfo.js
CHANGED
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
require("@polkadot/extension-mocks/chrome");
|
|
6
|
-
|
|
7
|
-
var _types = require("@polkadot/types");
|
|
8
|
-
|
|
9
|
-
var _uiKeyring = _interopRequireDefault(require("@polkadot/ui-keyring"));
|
|
10
|
-
|
|
11
|
-
var _utilCrypto = require("@polkadot/util-crypto");
|
|
12
|
-
|
|
13
|
-
var _index = require("../../stores/index.cjs");
|
|
14
|
-
|
|
15
|
-
var _Extension = _interopRequireDefault(require("./Extension.cjs"));
|
|
16
|
-
|
|
17
|
-
var _State = _interopRequireDefault(require("./State.cjs"));
|
|
18
|
-
|
|
19
|
-
var _Tabs = _interopRequireDefault(require("./Tabs.cjs"));
|
|
20
|
-
|
|
21
|
-
// Copyright 2019-2021 @polkadot/extension authors & contributors
|
|
22
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
23
|
-
describe('Extension', () => {
|
|
24
|
-
let extension;
|
|
25
|
-
let state;
|
|
26
|
-
let tabs;
|
|
27
|
-
const suri = 'seed sock milk update focus rotate barely fade car face mechanic mercy';
|
|
28
|
-
const password = 'passw0rd';
|
|
29
|
-
|
|
30
|
-
async function createExtension() {
|
|
31
|
-
await (0, _utilCrypto.cryptoWaitReady)();
|
|
32
|
-
|
|
33
|
-
_uiKeyring.default.loadAll({
|
|
34
|
-
store: new _index.AccountsStore()
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const authUrls = {};
|
|
38
|
-
authUrls['localhost:3000'] = {
|
|
39
|
-
count: 0,
|
|
40
|
-
id: '11',
|
|
41
|
-
isAllowed: true,
|
|
42
|
-
origin: 'example.com',
|
|
43
|
-
url: 'http://localhost:3000'
|
|
44
|
-
};
|
|
45
|
-
localStorage.setItem('authUrls', JSON.stringify(authUrls));
|
|
46
|
-
state = new _State.default();
|
|
47
|
-
tabs = new _Tabs.default(state);
|
|
48
|
-
return new _Extension.default(state);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const createAccount = async type => {
|
|
52
|
-
await extension.handle('id', 'pri(accounts.create.suri)', type && type === 'ethereum' ? {
|
|
53
|
-
name: 'parent',
|
|
54
|
-
password,
|
|
55
|
-
suri,
|
|
56
|
-
type
|
|
57
|
-
} : {
|
|
58
|
-
name: 'parent',
|
|
59
|
-
password,
|
|
60
|
-
suri
|
|
61
|
-
}, {});
|
|
62
|
-
const {
|
|
63
|
-
address
|
|
64
|
-
} = await extension.handle('id', 'pri(seed.validate)', type && type === 'ethereum' ? {
|
|
65
|
-
suri,
|
|
66
|
-
type
|
|
67
|
-
} : {
|
|
68
|
-
suri
|
|
69
|
-
}, {});
|
|
70
|
-
return address;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
beforeAll(async () => {
|
|
74
|
-
extension = await createExtension();
|
|
75
|
-
});
|
|
76
|
-
test('exports account from keyring', async () => {
|
|
77
|
-
const {
|
|
78
|
-
pair: {
|
|
79
|
-
address
|
|
80
|
-
}
|
|
81
|
-
} = _uiKeyring.default.addUri(suri, password);
|
|
82
|
-
|
|
83
|
-
const result = await extension.handle('id', 'pri(accounts.export)', {
|
|
84
|
-
address,
|
|
85
|
-
password
|
|
86
|
-
}, {});
|
|
87
|
-
expect(result.exportedJson.address).toBe(address);
|
|
88
|
-
expect(result.exportedJson.encoded).toBeDefined();
|
|
89
|
-
});
|
|
90
|
-
describe('account derivation', () => {
|
|
91
|
-
let address;
|
|
92
|
-
beforeEach(async () => {
|
|
93
|
-
address = await createAccount();
|
|
94
|
-
});
|
|
95
|
-
test('pri(derivation.validate) passes for valid suri', async () => {
|
|
96
|
-
const result = await extension.handle('id', 'pri(derivation.validate)', {
|
|
97
|
-
parentAddress: address,
|
|
98
|
-
parentPassword: password,
|
|
99
|
-
suri: '//path'
|
|
100
|
-
}, {});
|
|
101
|
-
expect(result).toStrictEqual({
|
|
102
|
-
address: '5FP3TT3EruYBNh8YM8yoxsreMx7uZv1J1zNX7fFhoC5enwmN',
|
|
103
|
-
suri: '//path'
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
test('pri(derivation.validate) throws for invalid suri', async () => {
|
|
107
|
-
await expect(extension.handle('id', 'pri(derivation.validate)', {
|
|
108
|
-
parentAddress: address,
|
|
109
|
-
parentPassword: password,
|
|
110
|
-
suri: 'invalid-path'
|
|
111
|
-
}, {})).rejects.toStrictEqual(new Error('"invalid-path" is not a valid derivation path'));
|
|
112
|
-
});
|
|
113
|
-
test('pri(derivation.validate) throws for invalid password', async () => {
|
|
114
|
-
await expect(extension.handle('id', 'pri(derivation.validate)', {
|
|
115
|
-
parentAddress: address,
|
|
116
|
-
parentPassword: 'invalid-password',
|
|
117
|
-
suri: '//path'
|
|
118
|
-
}, {})).rejects.toStrictEqual(new Error('invalid password'));
|
|
119
|
-
});
|
|
120
|
-
test('pri(derivation.create) adds a derived account', async () => {
|
|
121
|
-
await extension.handle('id', 'pri(derivation.create)', {
|
|
122
|
-
name: 'child',
|
|
123
|
-
parentAddress: address,
|
|
124
|
-
parentPassword: password,
|
|
125
|
-
password,
|
|
126
|
-
suri: '//path'
|
|
127
|
-
}, {});
|
|
128
|
-
expect(_uiKeyring.default.getAccounts()).toHaveLength(2);
|
|
129
|
-
});
|
|
130
|
-
test('pri(derivation.create) saves parent address in meta', async () => {
|
|
131
|
-
var _keyring$getAccount;
|
|
132
|
-
|
|
133
|
-
await extension.handle('id', 'pri(derivation.create)', {
|
|
134
|
-
name: 'child',
|
|
135
|
-
parentAddress: address,
|
|
136
|
-
parentPassword: password,
|
|
137
|
-
password,
|
|
138
|
-
suri: '//path'
|
|
139
|
-
}, {});
|
|
140
|
-
expect((_keyring$getAccount = _uiKeyring.default.getAccount('5FP3TT3EruYBNh8YM8yoxsreMx7uZv1J1zNX7fFhoC5enwmN')) === null || _keyring$getAccount === void 0 ? void 0 : _keyring$getAccount.meta.parentAddress).toEqual(address);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
describe('account management', () => {
|
|
144
|
-
let address;
|
|
145
|
-
beforeEach(async () => {
|
|
146
|
-
address = await createAccount();
|
|
147
|
-
});
|
|
148
|
-
test('pri(accounts.changePassword) changes account password', async () => {
|
|
149
|
-
const newPass = 'pa55word';
|
|
150
|
-
const wrongPass = 'ZZzzZZzz';
|
|
151
|
-
await expect(extension.handle('id', 'pri(accounts.changePassword)', {
|
|
152
|
-
address,
|
|
153
|
-
newPass,
|
|
154
|
-
oldPass: wrongPass
|
|
155
|
-
}, {})).rejects.toStrictEqual(new Error('oldPass is invalid'));
|
|
156
|
-
await expect(extension.handle('id', 'pri(accounts.changePassword)', {
|
|
157
|
-
address,
|
|
158
|
-
newPass,
|
|
159
|
-
oldPass: password
|
|
160
|
-
}, {})).resolves.toEqual(true);
|
|
161
|
-
|
|
162
|
-
const pair = _uiKeyring.default.getPair(address);
|
|
163
|
-
|
|
164
|
-
expect(pair.decodePkcs8(newPass)).toEqual(undefined);
|
|
165
|
-
expect(() => {
|
|
166
|
-
pair.decodePkcs8(password);
|
|
167
|
-
}).toThrowError('Unable to decode using the supplied passphrase');
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
describe('custom user extension', () => {
|
|
171
|
-
let address, payload, pair;
|
|
172
|
-
beforeEach(async () => {
|
|
173
|
-
address = await createAccount();
|
|
174
|
-
pair = _uiKeyring.default.getPair(address);
|
|
175
|
-
pair.decodePkcs8(password);
|
|
176
|
-
payload = {
|
|
177
|
-
address,
|
|
178
|
-
blockHash: '0xe1b1dda72998846487e4d858909d4f9a6bbd6e338e4588e5d809de16b1317b80',
|
|
179
|
-
blockNumber: '0x00000393',
|
|
180
|
-
era: '0x3601',
|
|
181
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
182
|
-
method: '0x040105fa8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4882380100',
|
|
183
|
-
nonce: '0x0000000000000000',
|
|
184
|
-
signedExtensions: ['CheckSpecVersion', 'CheckTxVersion', 'CheckGenesis', 'CheckMortality', 'CheckNonce', 'CheckWeight', 'ChargeTransactionPayment'],
|
|
185
|
-
specVersion: '0x00000026',
|
|
186
|
-
tip: '0x00000000000000000000000000000000',
|
|
187
|
-
transactionVersion: '0x00000005',
|
|
188
|
-
version: 4
|
|
189
|
-
};
|
|
190
|
-
});
|
|
191
|
-
test('signs with default signed extensions', async () => {
|
|
192
|
-
const registry = new _types.TypeRegistry();
|
|
193
|
-
registry.setSignedExtensions(payload.signedExtensions);
|
|
194
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', payload, {
|
|
195
|
-
version: payload.version
|
|
196
|
-
}).sign(pair);
|
|
197
|
-
tabs.handle('1615191860871.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {}).then(result => {
|
|
198
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
199
|
-
}).catch(err => console.log(err));
|
|
200
|
-
await expect(extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
|
|
201
|
-
id: state.allSignRequests[0].id,
|
|
202
|
-
password,
|
|
203
|
-
savePass: false
|
|
204
|
-
}, {})).resolves.toEqual(true);
|
|
205
|
-
});
|
|
206
|
-
test('signs with default signed extensions - ethereum', async () => {
|
|
207
|
-
const ethAddress = await createAccount('ethereum');
|
|
208
|
-
|
|
209
|
-
const ethPair = _uiKeyring.default.getPair(ethAddress);
|
|
210
|
-
|
|
211
|
-
ethPair.decodePkcs8(password);
|
|
212
|
-
const ethPayload = {
|
|
213
|
-
address: ethAddress,
|
|
214
|
-
blockHash: '0xf9fc354edc3ff49f43d5e2c14e3c609a0c4ba469ed091edf893d672993dc9bc0',
|
|
215
|
-
blockNumber: '0x00000393',
|
|
216
|
-
era: '0x3601',
|
|
217
|
-
genesisHash: '0xf9fc354edc3ff49f43d5e2c14e3c609a0c4ba469ed091edf893d672993dc9bc0',
|
|
218
|
-
method: '0x03003cd0a705a2dc65e5b1e1205896baa2be8a07c6e0070010a5d4e8',
|
|
219
|
-
nonce: '0x00000000',
|
|
220
|
-
signedExtensions: ['CheckSpecVersion', 'CheckTxVersion', 'CheckGenesis', 'CheckMortality', 'CheckNonce', 'CheckWeight', 'ChargeTransactionPayment'],
|
|
221
|
-
specVersion: '0x000003e9',
|
|
222
|
-
tip: '0x00000000000000000000000000000000',
|
|
223
|
-
transactionVersion: '0x00000002',
|
|
224
|
-
version: 4
|
|
225
|
-
};
|
|
226
|
-
const registry = new _types.TypeRegistry();
|
|
227
|
-
registry.setSignedExtensions(payload.signedExtensions);
|
|
228
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', ethPayload, {
|
|
229
|
-
version: ethPayload.version
|
|
230
|
-
}).sign(ethPair);
|
|
231
|
-
tabs.handle('1615191860871.5', 'pub(extrinsic.sign)', ethPayload, 'http://localhost:3000', {}).then(result => {
|
|
232
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
233
|
-
}).catch(err => console.log(err));
|
|
234
|
-
await expect(extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
|
|
235
|
-
id: state.allSignRequests[0].id,
|
|
236
|
-
password,
|
|
237
|
-
savePass: false
|
|
238
|
-
}, {})).resolves.toEqual(true);
|
|
239
|
-
});
|
|
240
|
-
test('signs with user extensions, known types', async () => {
|
|
241
|
-
const types = {};
|
|
242
|
-
const userExtensions = {
|
|
243
|
-
MyUserExtension: {
|
|
244
|
-
extrinsic: {
|
|
245
|
-
assetId: 'AssetId'
|
|
246
|
-
},
|
|
247
|
-
payload: {}
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
const meta = {
|
|
251
|
-
chain: 'Development',
|
|
252
|
-
color: '#191a2e',
|
|
253
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
254
|
-
icon: '',
|
|
255
|
-
specVersion: 38,
|
|
256
|
-
ss58Format: 0,
|
|
257
|
-
tokenDecimals: 12,
|
|
258
|
-
tokenSymbol: '',
|
|
259
|
-
types,
|
|
260
|
-
userExtensions
|
|
261
|
-
};
|
|
262
|
-
state.saveMetadata(meta);
|
|
263
|
-
const payload = {
|
|
264
|
-
address,
|
|
265
|
-
blockHash: '0xe1b1dda72998846487e4d858909d4f9a6bbd6e338e4588e5d809de16b1317b80',
|
|
266
|
-
blockNumber: '0x00000393',
|
|
267
|
-
era: '0x3601',
|
|
268
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
269
|
-
method: '0x040105fa8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4882380100',
|
|
270
|
-
nonce: '0x0000000000000000',
|
|
271
|
-
signedExtensions: ['MyUserExtension'],
|
|
272
|
-
specVersion: '0x00000026',
|
|
273
|
-
tip: '0x00000000000000000000000000000000',
|
|
274
|
-
transactionVersion: '0x00000005',
|
|
275
|
-
version: 4
|
|
276
|
-
};
|
|
277
|
-
const registry = new _types.TypeRegistry();
|
|
278
|
-
registry.setSignedExtensions(payload.signedExtensions, userExtensions);
|
|
279
|
-
registry.register(types);
|
|
280
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', payload, {
|
|
281
|
-
version: payload.version
|
|
282
|
-
}).sign(pair);
|
|
283
|
-
tabs.handle('1615191860771.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {}).then(result => {
|
|
284
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
285
|
-
}).catch(err => console.log(err));
|
|
286
|
-
await expect(extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
|
|
287
|
-
id: state.allSignRequests[0].id,
|
|
288
|
-
password,
|
|
289
|
-
savePass: false
|
|
290
|
-
}, {})).resolves.toEqual(true);
|
|
291
|
-
});
|
|
292
|
-
test('override default signed extension', async () => {
|
|
293
|
-
const types = {
|
|
294
|
-
FeeExchangeV1: {
|
|
295
|
-
assetId: 'Compact<AssetId>',
|
|
296
|
-
maxPayment: 'Compact<Balance>'
|
|
297
|
-
},
|
|
298
|
-
PaymentOptions: {
|
|
299
|
-
feeExchange: 'FeeExchangeV1',
|
|
300
|
-
tip: 'Compact<Balance>'
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
const userExtensions = {
|
|
304
|
-
ChargeTransactionPayment: {
|
|
305
|
-
extrinsic: {
|
|
306
|
-
transactionPayment: 'PaymentOptions'
|
|
307
|
-
},
|
|
308
|
-
payload: {}
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
const meta = {
|
|
312
|
-
chain: 'Development',
|
|
313
|
-
color: '#191a2e',
|
|
314
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
315
|
-
icon: '',
|
|
316
|
-
specVersion: 38,
|
|
317
|
-
ss58Format: 0,
|
|
318
|
-
tokenDecimals: 12,
|
|
319
|
-
tokenSymbol: '',
|
|
320
|
-
types,
|
|
321
|
-
userExtensions
|
|
322
|
-
};
|
|
323
|
-
state.saveMetadata(meta);
|
|
324
|
-
const registry = new _types.TypeRegistry();
|
|
325
|
-
registry.setSignedExtensions(payload.signedExtensions, userExtensions);
|
|
326
|
-
registry.register(types);
|
|
327
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', payload, {
|
|
328
|
-
version: payload.version
|
|
329
|
-
}).sign(pair);
|
|
330
|
-
tabs.handle('1615191860771.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {}).then(result => {
|
|
331
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
332
|
-
}).catch(err => console.log(err));
|
|
333
|
-
await expect(extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
|
|
334
|
-
id: state.allSignRequests[0].id,
|
|
335
|
-
password,
|
|
336
|
-
savePass: false
|
|
337
|
-
}, {})).resolves.toEqual(true);
|
|
338
|
-
});
|
|
339
|
-
test('signs with user extensions, additional types', async () => {
|
|
340
|
-
const types = {
|
|
341
|
-
myCustomType: {
|
|
342
|
-
feeExchange: 'Compact<AssetId>',
|
|
343
|
-
tip: 'Compact<Balance>'
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
const userExtensions = {
|
|
347
|
-
MyUserExtension: {
|
|
348
|
-
extrinsic: {
|
|
349
|
-
myCustomType: 'myCustomType'
|
|
350
|
-
},
|
|
351
|
-
payload: {}
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
const meta = {
|
|
355
|
-
chain: 'Development',
|
|
356
|
-
color: '#191a2e',
|
|
357
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
358
|
-
icon: '',
|
|
359
|
-
specVersion: 38,
|
|
360
|
-
ss58Format: 0,
|
|
361
|
-
tokenDecimals: 12,
|
|
362
|
-
tokenSymbol: '',
|
|
363
|
-
types,
|
|
364
|
-
userExtensions
|
|
365
|
-
};
|
|
366
|
-
state.saveMetadata(meta);
|
|
367
|
-
const payload = {
|
|
368
|
-
address,
|
|
369
|
-
blockHash: '0xe1b1dda72998846487e4d858909d4f9a6bbd6e338e4588e5d809de16b1317b80',
|
|
370
|
-
blockNumber: '0x00000393',
|
|
371
|
-
era: '0x3601',
|
|
372
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
373
|
-
method: '0x040105fa8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4882380100',
|
|
374
|
-
nonce: '0x0000000000000000',
|
|
375
|
-
signedExtensions: ['MyUserExtension', 'CheckTxVersion', 'CheckGenesis', 'CheckMortality', 'CheckNonce', 'CheckWeight', 'ChargeTransactionPayment'],
|
|
376
|
-
specVersion: '0x00000026',
|
|
377
|
-
tip: null,
|
|
378
|
-
transactionVersion: '0x00000005',
|
|
379
|
-
version: 4
|
|
380
|
-
};
|
|
381
|
-
const registry = new _types.TypeRegistry();
|
|
382
|
-
registry.setSignedExtensions(payload.signedExtensions, userExtensions);
|
|
383
|
-
registry.register(types);
|
|
384
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', payload, {
|
|
385
|
-
version: payload.version
|
|
386
|
-
}).sign(pair);
|
|
387
|
-
tabs.handle('1615191860771.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {}).then(result => {
|
|
388
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
389
|
-
}).catch(err => console.log(err));
|
|
390
|
-
await expect(extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
|
|
391
|
-
id: state.allSignRequests[0].id,
|
|
392
|
-
password,
|
|
393
|
-
savePass: false
|
|
394
|
-
}, {})).resolves.toEqual(true);
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@polkadot/extension-mocks/chrome';
|
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
// Copyright 2019-2021 @polkadot/extension authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import '@polkadot/extension-mocks/chrome';
|
|
4
|
-
import { TypeRegistry } from '@polkadot/types';
|
|
5
|
-
import keyring from '@polkadot/ui-keyring';
|
|
6
|
-
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
|
7
|
-
import { AccountsStore } from "../../stores/index.js";
|
|
8
|
-
import Extension from "./Extension.js";
|
|
9
|
-
import State from "./State.js";
|
|
10
|
-
import Tabs from "./Tabs.js";
|
|
11
|
-
describe('Extension', () => {
|
|
12
|
-
let extension;
|
|
13
|
-
let state;
|
|
14
|
-
let tabs;
|
|
15
|
-
const suri = 'seed sock milk update focus rotate barely fade car face mechanic mercy';
|
|
16
|
-
const password = 'passw0rd';
|
|
17
|
-
|
|
18
|
-
async function createExtension() {
|
|
19
|
-
await cryptoWaitReady();
|
|
20
|
-
keyring.loadAll({
|
|
21
|
-
store: new AccountsStore()
|
|
22
|
-
});
|
|
23
|
-
const authUrls = {};
|
|
24
|
-
authUrls['localhost:3000'] = {
|
|
25
|
-
count: 0,
|
|
26
|
-
id: '11',
|
|
27
|
-
isAllowed: true,
|
|
28
|
-
origin: 'example.com',
|
|
29
|
-
url: 'http://localhost:3000'
|
|
30
|
-
};
|
|
31
|
-
localStorage.setItem('authUrls', JSON.stringify(authUrls));
|
|
32
|
-
state = new State();
|
|
33
|
-
tabs = new Tabs(state);
|
|
34
|
-
return new Extension(state);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const createAccount = async type => {
|
|
38
|
-
await extension.handle('id', 'pri(accounts.create.suri)', type && type === 'ethereum' ? {
|
|
39
|
-
name: 'parent',
|
|
40
|
-
password,
|
|
41
|
-
suri,
|
|
42
|
-
type
|
|
43
|
-
} : {
|
|
44
|
-
name: 'parent',
|
|
45
|
-
password,
|
|
46
|
-
suri
|
|
47
|
-
}, {});
|
|
48
|
-
const {
|
|
49
|
-
address
|
|
50
|
-
} = await extension.handle('id', 'pri(seed.validate)', type && type === 'ethereum' ? {
|
|
51
|
-
suri,
|
|
52
|
-
type
|
|
53
|
-
} : {
|
|
54
|
-
suri
|
|
55
|
-
}, {});
|
|
56
|
-
return address;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
beforeAll(async () => {
|
|
60
|
-
extension = await createExtension();
|
|
61
|
-
});
|
|
62
|
-
test('exports account from keyring', async () => {
|
|
63
|
-
const {
|
|
64
|
-
pair: {
|
|
65
|
-
address
|
|
66
|
-
}
|
|
67
|
-
} = keyring.addUri(suri, password);
|
|
68
|
-
const result = await extension.handle('id', 'pri(accounts.export)', {
|
|
69
|
-
address,
|
|
70
|
-
password
|
|
71
|
-
}, {});
|
|
72
|
-
expect(result.exportedJson.address).toBe(address);
|
|
73
|
-
expect(result.exportedJson.encoded).toBeDefined();
|
|
74
|
-
});
|
|
75
|
-
describe('account derivation', () => {
|
|
76
|
-
let address;
|
|
77
|
-
beforeEach(async () => {
|
|
78
|
-
address = await createAccount();
|
|
79
|
-
});
|
|
80
|
-
test('pri(derivation.validate) passes for valid suri', async () => {
|
|
81
|
-
const result = await extension.handle('id', 'pri(derivation.validate)', {
|
|
82
|
-
parentAddress: address,
|
|
83
|
-
parentPassword: password,
|
|
84
|
-
suri: '//path'
|
|
85
|
-
}, {});
|
|
86
|
-
expect(result).toStrictEqual({
|
|
87
|
-
address: '5FP3TT3EruYBNh8YM8yoxsreMx7uZv1J1zNX7fFhoC5enwmN',
|
|
88
|
-
suri: '//path'
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
test('pri(derivation.validate) throws for invalid suri', async () => {
|
|
92
|
-
await expect(extension.handle('id', 'pri(derivation.validate)', {
|
|
93
|
-
parentAddress: address,
|
|
94
|
-
parentPassword: password,
|
|
95
|
-
suri: 'invalid-path'
|
|
96
|
-
}, {})).rejects.toStrictEqual(new Error('"invalid-path" is not a valid derivation path'));
|
|
97
|
-
});
|
|
98
|
-
test('pri(derivation.validate) throws for invalid password', async () => {
|
|
99
|
-
await expect(extension.handle('id', 'pri(derivation.validate)', {
|
|
100
|
-
parentAddress: address,
|
|
101
|
-
parentPassword: 'invalid-password',
|
|
102
|
-
suri: '//path'
|
|
103
|
-
}, {})).rejects.toStrictEqual(new Error('invalid password'));
|
|
104
|
-
});
|
|
105
|
-
test('pri(derivation.create) adds a derived account', async () => {
|
|
106
|
-
await extension.handle('id', 'pri(derivation.create)', {
|
|
107
|
-
name: 'child',
|
|
108
|
-
parentAddress: address,
|
|
109
|
-
parentPassword: password,
|
|
110
|
-
password,
|
|
111
|
-
suri: '//path'
|
|
112
|
-
}, {});
|
|
113
|
-
expect(keyring.getAccounts()).toHaveLength(2);
|
|
114
|
-
});
|
|
115
|
-
test('pri(derivation.create) saves parent address in meta', async () => {
|
|
116
|
-
var _keyring$getAccount;
|
|
117
|
-
|
|
118
|
-
await extension.handle('id', 'pri(derivation.create)', {
|
|
119
|
-
name: 'child',
|
|
120
|
-
parentAddress: address,
|
|
121
|
-
parentPassword: password,
|
|
122
|
-
password,
|
|
123
|
-
suri: '//path'
|
|
124
|
-
}, {});
|
|
125
|
-
expect((_keyring$getAccount = keyring.getAccount('5FP3TT3EruYBNh8YM8yoxsreMx7uZv1J1zNX7fFhoC5enwmN')) === null || _keyring$getAccount === void 0 ? void 0 : _keyring$getAccount.meta.parentAddress).toEqual(address);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
describe('account management', () => {
|
|
129
|
-
let address;
|
|
130
|
-
beforeEach(async () => {
|
|
131
|
-
address = await createAccount();
|
|
132
|
-
});
|
|
133
|
-
test('pri(accounts.changePassword) changes account password', async () => {
|
|
134
|
-
const newPass = 'pa55word';
|
|
135
|
-
const wrongPass = 'ZZzzZZzz';
|
|
136
|
-
await expect(extension.handle('id', 'pri(accounts.changePassword)', {
|
|
137
|
-
address,
|
|
138
|
-
newPass,
|
|
139
|
-
oldPass: wrongPass
|
|
140
|
-
}, {})).rejects.toStrictEqual(new Error('oldPass is invalid'));
|
|
141
|
-
await expect(extension.handle('id', 'pri(accounts.changePassword)', {
|
|
142
|
-
address,
|
|
143
|
-
newPass,
|
|
144
|
-
oldPass: password
|
|
145
|
-
}, {})).resolves.toEqual(true);
|
|
146
|
-
const pair = keyring.getPair(address);
|
|
147
|
-
expect(pair.decodePkcs8(newPass)).toEqual(undefined);
|
|
148
|
-
expect(() => {
|
|
149
|
-
pair.decodePkcs8(password);
|
|
150
|
-
}).toThrowError('Unable to decode using the supplied passphrase');
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
describe('custom user extension', () => {
|
|
154
|
-
let address, payload, pair;
|
|
155
|
-
beforeEach(async () => {
|
|
156
|
-
address = await createAccount();
|
|
157
|
-
pair = keyring.getPair(address);
|
|
158
|
-
pair.decodePkcs8(password);
|
|
159
|
-
payload = {
|
|
160
|
-
address,
|
|
161
|
-
blockHash: '0xe1b1dda72998846487e4d858909d4f9a6bbd6e338e4588e5d809de16b1317b80',
|
|
162
|
-
blockNumber: '0x00000393',
|
|
163
|
-
era: '0x3601',
|
|
164
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
165
|
-
method: '0x040105fa8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4882380100',
|
|
166
|
-
nonce: '0x0000000000000000',
|
|
167
|
-
signedExtensions: ['CheckSpecVersion', 'CheckTxVersion', 'CheckGenesis', 'CheckMortality', 'CheckNonce', 'CheckWeight', 'ChargeTransactionPayment'],
|
|
168
|
-
specVersion: '0x00000026',
|
|
169
|
-
tip: '0x00000000000000000000000000000000',
|
|
170
|
-
transactionVersion: '0x00000005',
|
|
171
|
-
version: 4
|
|
172
|
-
};
|
|
173
|
-
});
|
|
174
|
-
test('signs with default signed extensions', async () => {
|
|
175
|
-
const registry = new TypeRegistry();
|
|
176
|
-
registry.setSignedExtensions(payload.signedExtensions);
|
|
177
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', payload, {
|
|
178
|
-
version: payload.version
|
|
179
|
-
}).sign(pair);
|
|
180
|
-
tabs.handle('1615191860871.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {}).then(result => {
|
|
181
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
182
|
-
}).catch(err => console.log(err));
|
|
183
|
-
await expect(extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
|
|
184
|
-
id: state.allSignRequests[0].id,
|
|
185
|
-
password,
|
|
186
|
-
savePass: false
|
|
187
|
-
}, {})).resolves.toEqual(true);
|
|
188
|
-
});
|
|
189
|
-
test('signs with default signed extensions - ethereum', async () => {
|
|
190
|
-
const ethAddress = await createAccount('ethereum');
|
|
191
|
-
const ethPair = keyring.getPair(ethAddress);
|
|
192
|
-
ethPair.decodePkcs8(password);
|
|
193
|
-
const ethPayload = {
|
|
194
|
-
address: ethAddress,
|
|
195
|
-
blockHash: '0xf9fc354edc3ff49f43d5e2c14e3c609a0c4ba469ed091edf893d672993dc9bc0',
|
|
196
|
-
blockNumber: '0x00000393',
|
|
197
|
-
era: '0x3601',
|
|
198
|
-
genesisHash: '0xf9fc354edc3ff49f43d5e2c14e3c609a0c4ba469ed091edf893d672993dc9bc0',
|
|
199
|
-
method: '0x03003cd0a705a2dc65e5b1e1205896baa2be8a07c6e0070010a5d4e8',
|
|
200
|
-
nonce: '0x00000000',
|
|
201
|
-
signedExtensions: ['CheckSpecVersion', 'CheckTxVersion', 'CheckGenesis', 'CheckMortality', 'CheckNonce', 'CheckWeight', 'ChargeTransactionPayment'],
|
|
202
|
-
specVersion: '0x000003e9',
|
|
203
|
-
tip: '0x00000000000000000000000000000000',
|
|
204
|
-
transactionVersion: '0x00000002',
|
|
205
|
-
version: 4
|
|
206
|
-
};
|
|
207
|
-
const registry = new TypeRegistry();
|
|
208
|
-
registry.setSignedExtensions(payload.signedExtensions);
|
|
209
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', ethPayload, {
|
|
210
|
-
version: ethPayload.version
|
|
211
|
-
}).sign(ethPair);
|
|
212
|
-
tabs.handle('1615191860871.5', 'pub(extrinsic.sign)', ethPayload, 'http://localhost:3000', {}).then(result => {
|
|
213
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
214
|
-
}).catch(err => console.log(err));
|
|
215
|
-
await expect(extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
|
|
216
|
-
id: state.allSignRequests[0].id,
|
|
217
|
-
password,
|
|
218
|
-
savePass: false
|
|
219
|
-
}, {})).resolves.toEqual(true);
|
|
220
|
-
});
|
|
221
|
-
test('signs with user extensions, known types', async () => {
|
|
222
|
-
const types = {};
|
|
223
|
-
const userExtensions = {
|
|
224
|
-
MyUserExtension: {
|
|
225
|
-
extrinsic: {
|
|
226
|
-
assetId: 'AssetId'
|
|
227
|
-
},
|
|
228
|
-
payload: {}
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
const meta = {
|
|
232
|
-
chain: 'Development',
|
|
233
|
-
color: '#191a2e',
|
|
234
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
235
|
-
icon: '',
|
|
236
|
-
specVersion: 38,
|
|
237
|
-
ss58Format: 0,
|
|
238
|
-
tokenDecimals: 12,
|
|
239
|
-
tokenSymbol: '',
|
|
240
|
-
types,
|
|
241
|
-
userExtensions
|
|
242
|
-
};
|
|
243
|
-
state.saveMetadata(meta);
|
|
244
|
-
const payload = {
|
|
245
|
-
address,
|
|
246
|
-
blockHash: '0xe1b1dda72998846487e4d858909d4f9a6bbd6e338e4588e5d809de16b1317b80',
|
|
247
|
-
blockNumber: '0x00000393',
|
|
248
|
-
era: '0x3601',
|
|
249
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
250
|
-
method: '0x040105fa8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4882380100',
|
|
251
|
-
nonce: '0x0000000000000000',
|
|
252
|
-
signedExtensions: ['MyUserExtension'],
|
|
253
|
-
specVersion: '0x00000026',
|
|
254
|
-
tip: '0x00000000000000000000000000000000',
|
|
255
|
-
transactionVersion: '0x00000005',
|
|
256
|
-
version: 4
|
|
257
|
-
};
|
|
258
|
-
const registry = new TypeRegistry();
|
|
259
|
-
registry.setSignedExtensions(payload.signedExtensions, userExtensions);
|
|
260
|
-
registry.register(types);
|
|
261
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', payload, {
|
|
262
|
-
version: payload.version
|
|
263
|
-
}).sign(pair);
|
|
264
|
-
tabs.handle('1615191860771.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {}).then(result => {
|
|
265
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
266
|
-
}).catch(err => console.log(err));
|
|
267
|
-
await expect(extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
|
|
268
|
-
id: state.allSignRequests[0].id,
|
|
269
|
-
password,
|
|
270
|
-
savePass: false
|
|
271
|
-
}, {})).resolves.toEqual(true);
|
|
272
|
-
});
|
|
273
|
-
test('override default signed extension', async () => {
|
|
274
|
-
const types = {
|
|
275
|
-
FeeExchangeV1: {
|
|
276
|
-
assetId: 'Compact<AssetId>',
|
|
277
|
-
maxPayment: 'Compact<Balance>'
|
|
278
|
-
},
|
|
279
|
-
PaymentOptions: {
|
|
280
|
-
feeExchange: 'FeeExchangeV1',
|
|
281
|
-
tip: 'Compact<Balance>'
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
const userExtensions = {
|
|
285
|
-
ChargeTransactionPayment: {
|
|
286
|
-
extrinsic: {
|
|
287
|
-
transactionPayment: 'PaymentOptions'
|
|
288
|
-
},
|
|
289
|
-
payload: {}
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
const meta = {
|
|
293
|
-
chain: 'Development',
|
|
294
|
-
color: '#191a2e',
|
|
295
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
296
|
-
icon: '',
|
|
297
|
-
specVersion: 38,
|
|
298
|
-
ss58Format: 0,
|
|
299
|
-
tokenDecimals: 12,
|
|
300
|
-
tokenSymbol: '',
|
|
301
|
-
types,
|
|
302
|
-
userExtensions
|
|
303
|
-
};
|
|
304
|
-
state.saveMetadata(meta);
|
|
305
|
-
const registry = new TypeRegistry();
|
|
306
|
-
registry.setSignedExtensions(payload.signedExtensions, userExtensions);
|
|
307
|
-
registry.register(types);
|
|
308
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', payload, {
|
|
309
|
-
version: payload.version
|
|
310
|
-
}).sign(pair);
|
|
311
|
-
tabs.handle('1615191860771.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {}).then(result => {
|
|
312
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
313
|
-
}).catch(err => console.log(err));
|
|
314
|
-
await expect(extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
|
|
315
|
-
id: state.allSignRequests[0].id,
|
|
316
|
-
password,
|
|
317
|
-
savePass: false
|
|
318
|
-
}, {})).resolves.toEqual(true);
|
|
319
|
-
});
|
|
320
|
-
test('signs with user extensions, additional types', async () => {
|
|
321
|
-
const types = {
|
|
322
|
-
myCustomType: {
|
|
323
|
-
feeExchange: 'Compact<AssetId>',
|
|
324
|
-
tip: 'Compact<Balance>'
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
const userExtensions = {
|
|
328
|
-
MyUserExtension: {
|
|
329
|
-
extrinsic: {
|
|
330
|
-
myCustomType: 'myCustomType'
|
|
331
|
-
},
|
|
332
|
-
payload: {}
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
const meta = {
|
|
336
|
-
chain: 'Development',
|
|
337
|
-
color: '#191a2e',
|
|
338
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
339
|
-
icon: '',
|
|
340
|
-
specVersion: 38,
|
|
341
|
-
ss58Format: 0,
|
|
342
|
-
tokenDecimals: 12,
|
|
343
|
-
tokenSymbol: '',
|
|
344
|
-
types,
|
|
345
|
-
userExtensions
|
|
346
|
-
};
|
|
347
|
-
state.saveMetadata(meta);
|
|
348
|
-
const payload = {
|
|
349
|
-
address,
|
|
350
|
-
blockHash: '0xe1b1dda72998846487e4d858909d4f9a6bbd6e338e4588e5d809de16b1317b80',
|
|
351
|
-
blockNumber: '0x00000393',
|
|
352
|
-
era: '0x3601',
|
|
353
|
-
genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
|
|
354
|
-
method: '0x040105fa8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4882380100',
|
|
355
|
-
nonce: '0x0000000000000000',
|
|
356
|
-
signedExtensions: ['MyUserExtension', 'CheckTxVersion', 'CheckGenesis', 'CheckMortality', 'CheckNonce', 'CheckWeight', 'ChargeTransactionPayment'],
|
|
357
|
-
specVersion: '0x00000026',
|
|
358
|
-
tip: null,
|
|
359
|
-
transactionVersion: '0x00000005',
|
|
360
|
-
version: 4
|
|
361
|
-
};
|
|
362
|
-
const registry = new TypeRegistry();
|
|
363
|
-
registry.setSignedExtensions(payload.signedExtensions, userExtensions);
|
|
364
|
-
registry.register(types);
|
|
365
|
-
const signatureExpected = registry.createType('ExtrinsicPayload', payload, {
|
|
366
|
-
version: payload.version
|
|
367
|
-
}).sign(pair);
|
|
368
|
-
tabs.handle('1615191860771.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {}).then(result => {
|
|
369
|
-
expect(result === null || result === void 0 ? void 0 : result.signature).toEqual(signatureExpected.signature);
|
|
370
|
-
}).catch(err => console.log(err));
|
|
371
|
-
await expect(extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
|
|
372
|
-
id: state.allSignRequests[0].id,
|
|
373
|
-
password,
|
|
374
|
-
savePass: false
|
|
375
|
-
}, {})).resolves.toEqual(true);
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
});
|