@pezkuwi/extension-base 0.62.14 → 0.62.18
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 +16 -470
- package/src/background/RequestBytesSign.ts +28 -0
- package/src/background/RequestExtrinsicSign.ts +22 -0
- package/src/background/handlers/Extension.spec.ts +478 -0
- package/src/background/handlers/Extension.ts +690 -0
- package/src/background/handlers/State.ts +664 -0
- package/src/background/handlers/Tabs.ts +289 -0
- package/src/background/handlers/helpers.ts +14 -0
- package/src/background/handlers/index.ts +60 -0
- package/src/background/handlers/subscriptions.ts +32 -0
- package/src/background/index.ts +4 -0
- package/src/background/types.ts +432 -0
- package/src/bundle.ts +4 -0
- package/{defaults.js → src/defaults.ts} +15 -2
- package/src/index.ts +7 -0
- package/{packageDetect.js → src/packageDetect.ts} +8 -0
- package/src/packageInfo.ts +6 -0
- package/src/page/Accounts.ts +33 -0
- package/src/page/Injected.ts +33 -0
- package/src/page/Metadata.ts +22 -0
- package/src/page/PostMessageProvider.ts +182 -0
- package/src/page/Signer.ts +45 -0
- package/src/page/index.ts +89 -0
- package/src/page/types.ts +10 -0
- package/src/stores/Accounts.ts +28 -0
- package/src/stores/Base.ts +93 -0
- package/src/stores/Metadata.ts +17 -0
- package/{stores/index.js → src/stores/index.ts} +3 -0
- package/src/types.ts +12 -0
- package/src/utils/canDerive.ts +8 -0
- package/src/utils/getId.ts +10 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/portUtils.ts +65 -0
- package/tsconfig.build.json +16 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +18 -0
- package/tsconfig.spec.tsbuildinfo +1 -0
- package/LICENSE +0 -201
- package/background/RequestBytesSign.d.ts +0 -12
- package/background/RequestBytesSign.js +0 -12
- package/background/RequestExtrinsicSign.d.ts +0 -12
- package/background/RequestExtrinsicSign.js +0 -11
- package/background/handlers/Extension.d.ts +0 -49
- package/background/handlers/Extension.js +0 -489
- package/background/handlers/State.js +0 -478
- package/background/handlers/Tabs.d.ts +0 -25
- package/background/handlers/Tabs.js +0 -195
- package/background/handlers/helpers.js +0 -11
- package/background/handlers/index.d.ts +0 -3
- package/background/handlers/index.js +0 -40
- package/background/handlers/subscriptions.d.ts +0 -3
- package/background/handlers/subscriptions.js +0 -18
- package/background/index.d.ts +0 -1
- package/background/index.js +0 -1
- package/background/types.js +0 -1
- package/bundle.d.ts +0 -1
- package/bundle.js +0 -1
- package/cjs/background/RequestBytesSign.d.ts +0 -12
- package/cjs/background/RequestBytesSign.js +0 -15
- package/cjs/background/RequestExtrinsicSign.d.ts +0 -12
- package/cjs/background/RequestExtrinsicSign.js +0 -14
- package/cjs/background/handlers/Extension.d.ts +0 -49
- package/cjs/background/handlers/Extension.js +0 -492
- package/cjs/background/handlers/State.d.ts +0 -96
- package/cjs/background/handlers/State.js +0 -482
- package/cjs/background/handlers/Tabs.d.ts +0 -25
- package/cjs/background/handlers/Tabs.js +0 -199
- package/cjs/background/handlers/helpers.d.ts +0 -1
- package/cjs/background/handlers/helpers.js +0 -14
- package/cjs/background/handlers/index.d.ts +0 -3
- package/cjs/background/handlers/index.js +0 -46
- package/cjs/background/handlers/subscriptions.d.ts +0 -3
- package/cjs/background/handlers/subscriptions.js +0 -22
- package/cjs/background/index.d.ts +0 -1
- package/cjs/background/index.js +0 -7
- package/cjs/background/types.d.ts +0 -343
- package/cjs/background/types.js +0 -2
- package/cjs/bundle.d.ts +0 -1
- package/cjs/bundle.js +0 -5
- package/cjs/defaults.js +0 -16
- package/cjs/index.d.ts +0 -1
- package/cjs/index.js +0 -4
- package/cjs/package.json +0 -3
- package/cjs/packageDetect.d.ts +0 -1
- package/cjs/packageDetect.js +0 -8
- package/cjs/packageInfo.d.ts +0 -6
- package/cjs/packageInfo.js +0 -4
- package/cjs/page/Accounts.d.ts +0 -7
- package/cjs/page/Accounts.js +0 -24
- package/cjs/page/Injected.d.ts +0 -13
- package/cjs/page/Injected.js +0 -25
- package/cjs/page/Metadata.d.ts +0 -7
- package/cjs/page/Metadata.js +0 -15
- package/cjs/page/PostMessageProvider.d.ts +0 -63
- package/cjs/page/PostMessageProvider.js +0 -135
- package/cjs/page/Signer.d.ts +0 -8
- package/cjs/page/Signer.js +0 -29
- package/cjs/page/index.d.ts +0 -16
- package/cjs/page/index.js +0 -52
- package/cjs/page/types.d.ts +0 -6
- package/cjs/page/types.js +0 -2
- package/cjs/stores/Accounts.js +0 -21
- package/cjs/stores/Base.js +0 -70
- package/cjs/stores/Metadata.js +0 -13
- package/cjs/stores/index.js +0 -8
- package/cjs/types.js +0 -2
- package/cjs/utils/canDerive.d.ts +0 -2
- package/cjs/utils/canDerive.js +0 -6
- package/cjs/utils/getId.js +0 -8
- package/cjs/utils/index.d.ts +0 -1
- package/cjs/utils/index.js +0 -5
- package/cjs/utils/portUtils.d.ts +0 -13
- package/cjs/utils/portUtils.js +0 -49
- package/defaults.d.ts +0 -9
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/packageDetect.d.ts +0 -1
- package/packageInfo.d.ts +0 -6
- package/packageInfo.js +0 -1
- package/page/Accounts.d.ts +0 -7
- package/page/Accounts.js +0 -21
- package/page/Injected.d.ts +0 -13
- package/page/Injected.js +0 -21
- package/page/Metadata.d.ts +0 -7
- package/page/Metadata.js +0 -12
- package/page/PostMessageProvider.d.ts +0 -63
- package/page/PostMessageProvider.js +0 -132
- package/page/Signer.d.ts +0 -8
- package/page/Signer.js +0 -26
- package/page/index.d.ts +0 -16
- package/page/index.js +0 -45
- package/page/types.d.ts +0 -6
- package/page/types.js +0 -1
- package/stores/Accounts.d.ts +0 -6
- package/stores/Accounts.js +0 -17
- package/stores/Base.d.ts +0 -9
- package/stores/Base.js +0 -67
- package/stores/Metadata.d.ts +0 -5
- package/stores/Metadata.js +0 -9
- package/stores/index.d.ts +0 -2
- package/types.d.ts +0 -9
- package/types.js +0 -1
- package/utils/canDerive.d.ts +0 -2
- package/utils/canDerive.js +0 -3
- package/utils/getId.d.ts +0 -1
- package/utils/getId.js +0 -5
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -1
- package/utils/portUtils.d.ts +0 -13
- package/utils/portUtils.js +0 -43
- /package/{background → src/background}/handlers/State.d.ts +0 -0
- /package/{background → src/background}/handlers/helpers.d.ts +0 -0
- /package/{background → src/background}/types.d.ts +0 -0
- /package/{cjs → src}/defaults.d.ts +0 -0
- /package/{cjs → src}/stores/Accounts.d.ts +0 -0
- /package/{cjs → src}/stores/Base.d.ts +0 -0
- /package/{cjs → src}/stores/Metadata.d.ts +0 -0
- /package/{cjs → src}/stores/index.d.ts +0 -0
- /package/{cjs → src}/types.d.ts +0 -0
- /package/{cjs → src}/utils/getId.d.ts +0 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
// Copyright 2019-2026 @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
|
+
});
|