@subwallet/extension-base 0.3.6-0 → 0.3.6-1

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