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