@pezkuwi/extension-base 0.62.8 → 0.62.10

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.
Files changed (99) hide show
  1. package/package.json +2 -2
  2. package/src/background/RequestBytesSign.ts +0 -28
  3. package/src/background/RequestExtrinsicSign.ts +0 -22
  4. package/src/background/handlers/Extension.spec.ts +0 -478
  5. package/src/background/handlers/Extension.ts +0 -690
  6. package/src/background/handlers/State.ts +0 -664
  7. package/src/background/handlers/Tabs.ts +0 -289
  8. package/src/background/handlers/helpers.ts +0 -14
  9. package/src/background/handlers/index.ts +0 -60
  10. package/src/background/handlers/subscriptions.ts +0 -32
  11. package/src/background/index.ts +0 -4
  12. package/src/background/types.ts +0 -432
  13. package/src/bundle.ts +0 -4
  14. package/src/defaults.ts +0 -26
  15. package/src/index.ts +0 -7
  16. package/src/packageDetect.ts +0 -14
  17. package/src/packageInfo.ts +0 -6
  18. package/src/page/Accounts.ts +0 -33
  19. package/src/page/Injected.ts +0 -33
  20. package/src/page/Metadata.ts +0 -22
  21. package/src/page/PostMessageProvider.ts +0 -182
  22. package/src/page/Signer.ts +0 -45
  23. package/src/page/index.ts +0 -89
  24. package/src/page/types.ts +0 -10
  25. package/src/stores/Accounts.ts +0 -28
  26. package/src/stores/Base.ts +0 -93
  27. package/src/stores/Metadata.ts +0 -17
  28. package/src/stores/index.ts +0 -5
  29. package/src/types.ts +0 -12
  30. package/src/utils/canDerive.ts +0 -8
  31. package/src/utils/getId.ts +0 -10
  32. package/src/utils/index.ts +0 -4
  33. package/src/utils/portUtils.ts +0 -65
  34. package/tsconfig.build.json +0 -16
  35. package/tsconfig.build.tsbuildinfo +0 -1
  36. package/tsconfig.spec.json +0 -18
  37. package/tsconfig.spec.tsbuildinfo +0 -1
  38. /package/{build/background → background}/RequestBytesSign.d.ts +0 -0
  39. /package/{build/background → background}/RequestBytesSign.js +0 -0
  40. /package/{build/background → background}/RequestExtrinsicSign.d.ts +0 -0
  41. /package/{build/background → background}/RequestExtrinsicSign.js +0 -0
  42. /package/{build/background → background}/handlers/Extension.d.ts +0 -0
  43. /package/{build/background → background}/handlers/Extension.js +0 -0
  44. /package/{build/background → background}/handlers/State.d.ts +0 -0
  45. /package/{build/background → background}/handlers/State.js +0 -0
  46. /package/{build/background → background}/handlers/Tabs.d.ts +0 -0
  47. /package/{build/background → background}/handlers/Tabs.js +0 -0
  48. /package/{build/background → background}/handlers/helpers.d.ts +0 -0
  49. /package/{build/background → background}/handlers/helpers.js +0 -0
  50. /package/{build/background → background}/handlers/index.d.ts +0 -0
  51. /package/{build/background → background}/handlers/index.js +0 -0
  52. /package/{build/background → background}/handlers/subscriptions.d.ts +0 -0
  53. /package/{build/background → background}/handlers/subscriptions.js +0 -0
  54. /package/{build/background → background}/index.d.ts +0 -0
  55. /package/{build/background → background}/index.js +0 -0
  56. /package/{build/background → background}/types.d.ts +0 -0
  57. /package/{build/background → background}/types.js +0 -0
  58. /package/{build/bundle.d.ts → bundle.d.ts} +0 -0
  59. /package/{build/bundle.js → bundle.js} +0 -0
  60. /package/{build/defaults.d.ts → defaults.d.ts} +0 -0
  61. /package/{build/defaults.js → defaults.js} +0 -0
  62. /package/{build/index.d.ts → index.d.ts} +0 -0
  63. /package/{build/index.js → index.js} +0 -0
  64. /package/{build/packageDetect.d.ts → packageDetect.d.ts} +0 -0
  65. /package/{build/packageDetect.js → packageDetect.js} +0 -0
  66. /package/{build/packageInfo.d.ts → packageInfo.d.ts} +0 -0
  67. /package/{build/packageInfo.js → packageInfo.js} +0 -0
  68. /package/{build/page → page}/Accounts.d.ts +0 -0
  69. /package/{build/page → page}/Accounts.js +0 -0
  70. /package/{build/page → page}/Injected.d.ts +0 -0
  71. /package/{build/page → page}/Injected.js +0 -0
  72. /package/{build/page → page}/Metadata.d.ts +0 -0
  73. /package/{build/page → page}/Metadata.js +0 -0
  74. /package/{build/page → page}/PostMessageProvider.d.ts +0 -0
  75. /package/{build/page → page}/PostMessageProvider.js +0 -0
  76. /package/{build/page → page}/Signer.d.ts +0 -0
  77. /package/{build/page → page}/Signer.js +0 -0
  78. /package/{build/page → page}/index.d.ts +0 -0
  79. /package/{build/page → page}/index.js +0 -0
  80. /package/{build/page → page}/types.d.ts +0 -0
  81. /package/{build/page → page}/types.js +0 -0
  82. /package/{build/stores → stores}/Accounts.d.ts +0 -0
  83. /package/{build/stores → stores}/Accounts.js +0 -0
  84. /package/{build/stores → stores}/Base.d.ts +0 -0
  85. /package/{build/stores → stores}/Base.js +0 -0
  86. /package/{build/stores → stores}/Metadata.d.ts +0 -0
  87. /package/{build/stores → stores}/Metadata.js +0 -0
  88. /package/{build/stores → stores}/index.d.ts +0 -0
  89. /package/{build/stores → stores}/index.js +0 -0
  90. /package/{build/types.d.ts → types.d.ts} +0 -0
  91. /package/{build/types.js → types.js} +0 -0
  92. /package/{build/utils → utils}/canDerive.d.ts +0 -0
  93. /package/{build/utils → utils}/canDerive.js +0 -0
  94. /package/{build/utils → utils}/getId.d.ts +0 -0
  95. /package/{build/utils → utils}/getId.js +0 -0
  96. /package/{build/utils → utils}/index.d.ts +0 -0
  97. /package/{build/utils → utils}/index.js +0 -0
  98. /package/{build/utils → utils}/portUtils.d.ts +0 -0
  99. /package/{build/utils → utils}/portUtils.js +0 -0
package/package.json CHANGED
@@ -18,13 +18,13 @@
18
18
  "./packageDetect.cjs"
19
19
  ],
20
20
  "type": "module",
21
- "version": "0.62.8",
21
+ "version": "0.62.10",
22
22
  "main": "index.js",
23
23
  "dependencies": {
24
24
  "@pezkuwi/api": "^16.5.3",
25
25
  "@pezkuwi/extension-chains": "0.62.6",
26
26
  "@pezkuwi/extension-dapp": "0.62.6",
27
- "@pezkuwi/extension-inject": "0.62.6",
27
+ "@pezkuwi/extension-inject": "0.62.10",
28
28
  "@pezkuwi/keyring": "^14.0.5",
29
29
  "@pezkuwi/networks": "^14.0.5",
30
30
  "@pezkuwi/phishing": "^0.25.23",
@@ -1,28 +0,0 @@
1
- // Copyright 2019-2025 @pezkuwi/extension-base authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { KeyringPair } from '@pezkuwi/keyring/types';
5
- import type { TypeRegistry } from '@pezkuwi/types';
6
- import type { SignerPayloadRaw } from '@pezkuwi/types/types';
7
- import type { HexString } from '@pezkuwi/util/types';
8
- import type { RequestSign } from './types.js';
9
-
10
- import { u8aToHex, u8aWrapBytes } from '@pezkuwi/util';
11
-
12
- export default class RequestBytesSign implements RequestSign {
13
- public readonly payload: SignerPayloadRaw;
14
-
15
- constructor (payload: SignerPayloadRaw) {
16
- this.payload = payload;
17
- }
18
-
19
- sign (_registry: TypeRegistry, pair: KeyringPair): { signature: HexString } {
20
- return {
21
- signature: u8aToHex(
22
- pair.sign(
23
- u8aWrapBytes(this.payload.data)
24
- )
25
- )
26
- };
27
- }
28
- }
@@ -1,22 +0,0 @@
1
- // Copyright 2019-2025 @pezkuwi/extension-base authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { KeyringPair } from '@pezkuwi/keyring/types';
5
- import type { TypeRegistry } from '@pezkuwi/types';
6
- import type { SignerPayloadJSON } from '@pezkuwi/types/types';
7
- import type { HexString } from '@pezkuwi/util/types';
8
- import type { RequestSign } from './types.js';
9
-
10
- export default class RequestExtrinsicSign implements RequestSign {
11
- public readonly payload: SignerPayloadJSON;
12
-
13
- constructor (payload: SignerPayloadJSON) {
14
- this.payload = payload;
15
- }
16
-
17
- sign (registry: TypeRegistry, pair: KeyringPair): { signature: HexString } {
18
- return registry
19
- .createType('ExtrinsicPayload', this.payload, { version: this.payload.version })
20
- .sign(pair);
21
- }
22
- }
@@ -1,478 +0,0 @@
1
- // Copyright 2019-2025 @pezkuwi/extension-base authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- /* global chrome */
5
-
6
- import '@pezkuwi/extension-mocks/chrome';
7
-
8
- import type * as _ from '@pezkuwi/dev-test/globals.d.ts';
9
- import type { ResponseSigning } from '@pezkuwi/extension-base/background/types';
10
- import type { MetadataDef } from '@pezkuwi/extension-inject/types';
11
- import type { KeyringPair } from '@pezkuwi/keyring/types';
12
- import type { ExtDef } from '@pezkuwi/types/extrinsic/signedExtensions/types';
13
- import type { SignerPayloadJSON } from '@pezkuwi/types/types';
14
- import type { KeypairType } from '@pezkuwi/util-crypto/types';
15
-
16
- import { TypeRegistry } from '@pezkuwi/types';
17
- import keyring from '@pezkuwi/ui-keyring';
18
- import { cryptoWaitReady } from '@pezkuwi/util-crypto';
19
-
20
- import { AccountsStore } from '../../stores/index.js';
21
- import Extension from './Extension.js';
22
- import State from './State.js';
23
- import Tabs from './Tabs.js';
24
-
25
- describe('Extension', () => {
26
- let extension: Extension;
27
- let state: State;
28
- let tabs: Tabs;
29
- const suri = 'seed sock milk update focus rotate barely fade car face mechanic mercy';
30
- const password = 'passw0rd';
31
-
32
- async function createExtension (): Promise<Extension> {
33
- try {
34
- await cryptoWaitReady();
35
-
36
- keyring.loadAll({ store: new AccountsStore() });
37
-
38
- state = new State({}, 0);
39
- await state.init();
40
- tabs = new Tabs(state);
41
-
42
- return new Extension(state);
43
- } catch (e) {
44
- console.error(e);
45
-
46
- throw e;
47
- }
48
- }
49
-
50
- const createAccount = async (type?: KeypairType): Promise<string> => {
51
- await extension.handle('id', 'pri(accounts.create.suri)', type && type === 'ethereum'
52
- ? {
53
- name: 'parent',
54
- password,
55
- suri,
56
- type
57
- }
58
- : {
59
- name: 'parent',
60
- password,
61
- suri
62
- }, {} as chrome.runtime.Port);
63
- const { address } = await extension.handle('id', 'pri(seed.validate)', type && type === 'ethereum'
64
- ? {
65
- suri,
66
- type
67
- }
68
- : {
69
- suri
70
- }, {} as chrome.runtime.Port);
71
-
72
- return address;
73
- };
74
-
75
- beforeAll(async () => {
76
- extension = await createExtension();
77
- });
78
-
79
- it('exports account from keyring', async () => {
80
- const { pair: { address } } = keyring.addUri(suri, password);
81
- const result = await extension.handle('id', 'pri(accounts.export)', {
82
- address,
83
- password
84
- }, {} as chrome.runtime.Port);
85
-
86
- expect(result.exportedJson.address).toBe(address);
87
- expect(result.exportedJson.encoded).toBeDefined();
88
- });
89
-
90
- describe('account derivation', () => {
91
- let address: string;
92
-
93
- beforeEach(async () => {
94
- address = await createAccount();
95
- });
96
-
97
- it('pri(derivation.validate) passes for valid suri', async () => {
98
- const result = await extension.handle('id', 'pri(derivation.validate)', {
99
- parentAddress: address,
100
- parentPassword: password,
101
- suri: '//path'
102
- }, {} as chrome.runtime.Port);
103
-
104
- expect(result).toEqual({
105
- address: '5FP3TT3EruYBNh8YM8yoxsreMx7uZv1J1zNX7fFhoC5enwmN',
106
- suri: '//path'
107
- });
108
- });
109
-
110
- it('pri(derivation.validate) throws for invalid suri', async () => {
111
- await expect(extension.handle('id', 'pri(derivation.validate)', {
112
- parentAddress: address,
113
- parentPassword: password,
114
- suri: 'invalid-path'
115
- }, {} as chrome.runtime.Port)).rejects.toThrow(/is not a valid derivation path/);
116
- });
117
-
118
- it('pri(derivation.validate) throws for invalid password', async () => {
119
- await expect(extension.handle('id', 'pri(derivation.validate)', {
120
- parentAddress: address,
121
- parentPassword: 'invalid-password',
122
- suri: '//path'
123
- }, {} as chrome.runtime.Port)).rejects.toThrow(/invalid password/);
124
- });
125
-
126
- it('pri(derivation.create) adds a derived account', async () => {
127
- await extension.handle('id', 'pri(derivation.create)', {
128
- name: 'child',
129
- parentAddress: address,
130
- parentPassword: password,
131
- password,
132
- suri: '//path'
133
- }, {} as chrome.runtime.Port);
134
- expect(keyring.getAccounts()).toHaveLength(2);
135
- });
136
-
137
- it('pri(derivation.create) saves parent address in meta', async () => {
138
- await extension.handle('id', 'pri(derivation.create)', {
139
- name: 'child',
140
- parentAddress: address,
141
- parentPassword: password,
142
- password,
143
- suri: '//path'
144
- }, {} as chrome.runtime.Port);
145
- expect(keyring.getAccount('5FP3TT3EruYBNh8YM8yoxsreMx7uZv1J1zNX7fFhoC5enwmN')?.meta.parentAddress).toEqual(address);
146
- });
147
- });
148
-
149
- describe('account management', () => {
150
- let address: string;
151
-
152
- beforeEach(async () => {
153
- address = await createAccount();
154
- });
155
-
156
- it('pri(accounts.changePassword) changes account password', async () => {
157
- const newPass = 'pa55word';
158
- const wrongPass = 'ZZzzZZzz';
159
-
160
- await expect(extension.handle('id', 'pri(accounts.changePassword)', {
161
- address,
162
- newPass,
163
- oldPass: wrongPass
164
- }, {} as chrome.runtime.Port)).rejects.toThrow(/oldPass is invalid/);
165
-
166
- const res = await extension.handle('id', 'pri(accounts.changePassword)', {
167
- address,
168
- newPass,
169
- oldPass: password
170
- }, {} as chrome.runtime.Port);
171
-
172
- expect(res).toEqual(true);
173
-
174
- const pair = keyring.getPair(address);
175
-
176
- expect(pair.decodePkcs8(newPass)).toEqual(undefined);
177
-
178
- expect(() => {
179
- pair.decodePkcs8(password);
180
- }).toThrow(/Unable to decode using the supplied passphrase/);
181
- });
182
- });
183
-
184
- describe('custom user extension', () => {
185
- let address: string, payload: SignerPayloadJSON, pair: KeyringPair;
186
-
187
- beforeEach(async () => {
188
- address = await createAccount();
189
- pair = keyring.getPair(address);
190
- pair.decodePkcs8(password);
191
- payload = {
192
- address,
193
- blockHash: '0xe1b1dda72998846487e4d858909d4f9a6bbd6e338e4588e5d809de16b1317b80',
194
- blockNumber: '0x00000393',
195
- era: '0x3601',
196
- genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
197
- method: '0x040105fa8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4882380100',
198
- nonce: '0x0000000000000000',
199
- signedExtensions: ['CheckSpecVersion', 'CheckTxVersion', 'CheckGenesis', 'CheckMortality', 'CheckNonce', 'CheckWeight', 'ChargeTransactionPayment'],
200
- specVersion: '0x00000026',
201
- tip: '0x00000000000000000000000000000000',
202
- transactionVersion: '0x00000005',
203
- version: 4
204
- };
205
- });
206
-
207
- it('signs with default signed extensions', async () => {
208
- const registry = new TypeRegistry();
209
-
210
- registry.setSignedExtensions(payload.signedExtensions);
211
-
212
- const signatureExpected = registry
213
- .createType('ExtrinsicPayload', payload, { version: payload.version }).sign(pair);
214
-
215
- // eslint-disable-next-line jest/valid-expect-in-promise
216
- tabs.handle('1615191860871.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {} as chrome.runtime.Port)
217
- .then((result) => {
218
- // eslint-disable-next-line jest/no-conditional-expect
219
- expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
220
- }).catch((err) => console.log(err));
221
-
222
- const res = await extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
223
- id: state.allSignRequests[0].id,
224
- password,
225
- savePass: false
226
- }, {} as chrome.runtime.Port);
227
-
228
- expect(res).toEqual(true);
229
- });
230
-
231
- it('signs with default signed extensions - ethereum', async () => {
232
- const ethAddress = await createAccount('ethereum');
233
- const ethPair = keyring.getPair(ethAddress);
234
-
235
- ethPair.decodePkcs8(password);
236
- const ethPayload: SignerPayloadJSON = {
237
- address: ethAddress,
238
- blockHash: '0xf9fc354edc3ff49f43d5e2c14e3c609a0c4ba469ed091edf893d672993dc9bc0',
239
- blockNumber: '0x00000393',
240
- era: '0x3601',
241
- genesisHash: '0xf9fc354edc3ff49f43d5e2c14e3c609a0c4ba469ed091edf893d672993dc9bc0',
242
- method: '0x03003cd0a705a2dc65e5b1e1205896baa2be8a07c6e0070010a5d4e8',
243
- nonce: '0x00000000',
244
- signedExtensions: [
245
- 'CheckSpecVersion',
246
- 'CheckTxVersion',
247
- 'CheckGenesis',
248
- 'CheckMortality',
249
- 'CheckNonce',
250
- 'CheckWeight',
251
- 'ChargeTransactionPayment'
252
- ],
253
- specVersion: '0x000003e9',
254
- tip: '0x00000000000000000000000000000000',
255
- transactionVersion: '0x00000002',
256
- version: 4
257
- };
258
- const registry = new TypeRegistry();
259
-
260
- registry.setSignedExtensions(payload.signedExtensions);
261
-
262
- const signatureExpected = registry
263
- .createType('ExtrinsicPayload', ethPayload, { version: ethPayload.version }).sign(ethPair);
264
-
265
- // eslint-disable-next-line jest/valid-expect-in-promise
266
- tabs.handle('1615191860871.5', 'pub(extrinsic.sign)', ethPayload, 'http://localhost:3000', {} as chrome.runtime.Port)
267
- .then((result) => {
268
- // eslint-disable-next-line jest/no-conditional-expect
269
- expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
270
- }).catch((err) => console.log(err));
271
-
272
- const res = await extension.handle('1615192072290.7', 'pri(signing.approve.password)', {
273
- id: state.allSignRequests[0].id,
274
- password,
275
- savePass: false
276
- }, {} as chrome.runtime.Port);
277
-
278
- expect(res).toEqual(true);
279
- });
280
-
281
- it('signs with user extensions, known types', async () => {
282
- const types = {} as unknown as Record<string, string>;
283
-
284
- const userExtensions = {
285
- MyUserExtension: {
286
- extrinsic: {
287
- assetId: 'AssetId'
288
- },
289
- payload: {}
290
- }
291
- } as unknown as ExtDef;
292
-
293
- const meta: MetadataDef = {
294
- chain: 'Development',
295
- color: '#191a2e',
296
- genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
297
- icon: '',
298
- specVersion: 38,
299
- ss58Format: 0,
300
- tokenDecimals: 12,
301
- tokenSymbol: '',
302
- types,
303
- userExtensions
304
- };
305
-
306
- await state.saveMetadata(meta);
307
-
308
- const payload: SignerPayloadJSON = {
309
- address,
310
- blockHash: '0xe1b1dda72998846487e4d858909d4f9a6bbd6e338e4588e5d809de16b1317b80',
311
- blockNumber: '0x00000393',
312
- era: '0x3601',
313
- genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
314
- method: '0x040105fa8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4882380100',
315
- nonce: '0x0000000000000000',
316
- signedExtensions: ['MyUserExtension'],
317
- specVersion: '0x00000026',
318
- tip: '0x00000000000000000000000000000000',
319
- transactionVersion: '0x00000005',
320
- version: 4
321
- };
322
-
323
- const registry = new TypeRegistry();
324
-
325
- registry.setSignedExtensions(payload.signedExtensions, userExtensions);
326
- registry.register(types);
327
-
328
- const signatureExpected = registry
329
- .createType('ExtrinsicPayload', payload, { version: payload.version }).sign(pair);
330
-
331
- // eslint-disable-next-line jest/valid-expect-in-promise
332
- tabs.handle('1615191860771.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {} as chrome.runtime.Port)
333
- .then((result) => {
334
- // eslint-disable-next-line jest/no-conditional-expect
335
- expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
336
- }).catch((err) => console.log(err));
337
-
338
- const res = await extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
339
- id: state.allSignRequests[0].id,
340
- password,
341
- savePass: false
342
- }, {} as chrome.runtime.Port);
343
-
344
- expect(res).toEqual(true);
345
- });
346
-
347
- it('override default signed extension', async () => {
348
- const types = {
349
- FeeExchangeV1: {
350
- assetId: 'Compact<AssetId>',
351
- maxPayment: 'Compact<Balance>'
352
- },
353
- PaymentOptions: {
354
- feeExchange: 'FeeExchangeV1',
355
- tip: 'Compact<Balance>'
356
- }
357
- } as unknown as Record<string, string>;
358
-
359
- const userExtensions = {
360
- ChargeTransactionPayment: {
361
- extrinsic: {
362
- transactionPayment: 'PaymentOptions'
363
- },
364
- payload: {}
365
- }
366
- } as unknown as ExtDef;
367
-
368
- const meta: MetadataDef = {
369
- chain: 'Development',
370
- color: '#191a2e',
371
- genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
372
- icon: '',
373
- specVersion: 38,
374
- ss58Format: 0,
375
- tokenDecimals: 12,
376
- tokenSymbol: '',
377
- types,
378
- userExtensions
379
- };
380
-
381
- await state.saveMetadata(meta);
382
-
383
- const registry = new TypeRegistry();
384
-
385
- registry.setSignedExtensions(payload.signedExtensions, userExtensions);
386
- registry.register(types);
387
-
388
- const signatureExpected = registry
389
- .createType('ExtrinsicPayload', payload, { version: payload.version }).sign(pair);
390
-
391
- // eslint-disable-next-line jest/valid-expect-in-promise
392
- tabs.handle('1615191860771.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {} as chrome.runtime.Port)
393
- .then((result) => {
394
- // eslint-disable-next-line jest/no-conditional-expect
395
- expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
396
- }).catch((err) => console.log(err));
397
-
398
- const res = await extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
399
- id: state.allSignRequests[0].id,
400
- password,
401
- savePass: false
402
- }, {} as chrome.runtime.Port);
403
-
404
- expect(res).toEqual(true);
405
- });
406
-
407
- it('signs with user extensions, additional types', async () => {
408
- const types = {
409
- myCustomType: {
410
- feeExchange: 'Compact<AssetId>',
411
- tip: 'Compact<Balance>'
412
- }
413
- } as unknown as Record<string, string>;
414
-
415
- const userExtensions = {
416
- MyUserExtension: {
417
- extrinsic: {
418
- myCustomType: 'myCustomType'
419
- },
420
- payload: {}
421
- }
422
- } as unknown as ExtDef;
423
-
424
- const meta: MetadataDef = {
425
- chain: 'Development',
426
- color: '#191a2e',
427
- genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
428
- icon: '',
429
- specVersion: 38,
430
- ss58Format: 0,
431
- tokenDecimals: 12,
432
- tokenSymbol: '',
433
- types,
434
- userExtensions
435
- };
436
-
437
- await state.saveMetadata(meta);
438
-
439
- const payload = {
440
- address,
441
- blockHash: '0xe1b1dda72998846487e4d858909d4f9a6bbd6e338e4588e5d809de16b1317b80',
442
- blockNumber: '0x00000393',
443
- era: '0x3601',
444
- genesisHash: '0x242a54b35e1aad38f37b884eddeb71f6f9931b02fac27bf52dfb62ef754e5e62',
445
- method: '0x040105fa8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4882380100',
446
- nonce: '0x0000000000000000',
447
- signedExtensions: ['MyUserExtension', 'CheckTxVersion', 'CheckGenesis', 'CheckMortality', 'CheckNonce', 'CheckWeight', 'ChargeTransactionPayment'],
448
- specVersion: '0x00000026',
449
- tip: null,
450
- transactionVersion: '0x00000005',
451
- version: 4
452
- } as unknown as SignerPayloadJSON;
453
-
454
- const registry = new TypeRegistry();
455
-
456
- registry.setSignedExtensions(payload.signedExtensions, userExtensions);
457
- registry.register(types);
458
-
459
- const signatureExpected = registry
460
- .createType('ExtrinsicPayload', payload, { version: payload.version }).sign(pair);
461
-
462
- // eslint-disable-next-line jest/valid-expect-in-promise
463
- tabs.handle('1615191860771.5', 'pub(extrinsic.sign)', payload, 'http://localhost:3000', {} as chrome.runtime.Port)
464
- .then((result) => {
465
- // eslint-disable-next-line jest/no-conditional-expect
466
- expect((result as ResponseSigning)?.signature).toEqual(signatureExpected.signature);
467
- }).catch((err) => console.log(err));
468
-
469
- const res = await extension.handle('1615192062290.7', 'pri(signing.approve.password)', {
470
- id: state.allSignRequests[0].id,
471
- password,
472
- savePass: false
473
- }, {} as chrome.runtime.Port);
474
-
475
- expect(res).toEqual(true);
476
- });
477
- });
478
- });