@onekeyfe/hd-core 1.0.12-alpha.0 → 1.0.12-alpha.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.
@@ -1,6 +1,6 @@
1
1
  import { BaseMethod } from '../BaseMethod';
2
2
  import { CoreApi } from '../../types';
3
- import type { AllNetworkAddress, AllNetworkAddressParams, INetwork } from '../../types/api/allNetworkGetAddress';
3
+ import type { AllNetworkAddress, AllNetworkAddressParams, CommonResponseParams, INetwork } from '../../types/api/allNetworkGetAddress';
4
4
  export default class AllNetworkGetAddress extends BaseMethod<{
5
5
  address_n: number[];
6
6
  show_display: boolean;
@@ -13,8 +13,15 @@ export default class AllNetworkGetAddress extends BaseMethod<{
13
13
  payload: AllNetworkAddressParams;
14
14
  }): {
15
15
  methodName: keyof CoreApi;
16
- params: Parameters<CoreApi[keyof CoreApi]>[0];
16
+ params: Parameters<CoreApi[keyof CoreApi]>[0] & {
17
+ originPayload: AllNetworkAddressParams;
18
+ };
19
+ dependOnMethods: {
20
+ methodName: keyof CoreApi;
21
+ params: Parameters<CoreApi[keyof CoreApi]>[0];
22
+ }[] | undefined;
17
23
  };
24
+ callMethod(methodName: keyof CoreApi, params: any, baseParams: CommonResponseParams): Promise<AllNetworkAddress>;
18
25
  run(): Promise<AllNetworkAddress[]>;
19
26
  }
20
27
  //# sourceMappingURL=AllNetworkGetAddress.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AllNetworkGetAddress.d.ts","sourceRoot":"","sources":["../../../src/api/allnetwork/AllNetworkGetAddress.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,KAAK,EACV,iBAAiB,EACjB,uBAAuB,EACvB,QAAQ,EACT,MAAM,sCAAsC,CAAC;AAuM9C,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,UAAU,CA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AE,aAAa,EAAE,uBAAuB,CAAA;SAAE,CAAC;QAC3F,eAAe,EACX;YACE,UAAU,EAAE,MAAM,OAAO,CAAC;YAC1B,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/C,EAAE,GACH,SAAS,CAAC;KACf;IAyBK,UAAU,CAAC,UAAU,EAAE,MAAM,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,oBAAoB;IAwCnF,GAAG;CAiDV"}
package/dist/index.d.ts CHANGED
@@ -655,7 +655,7 @@ interface CardanoSignedTxData {
655
655
  auxiliaryDataSupplement?: CardanoAuxiliaryDataSupplement;
656
656
  }
657
657
 
658
- type INetwork = 'evm' | 'btc' | 'tbtc' | 'doge' | 'neurai' | 'ltc' | 'bch' | 'sol' | 'algo' | 'near' | 'stc' | 'cfx' | 'tron' | 'aptos' | 'xrp' | 'cosmos' | 'ada' | 'sui' | 'fil' | 'dot' | 'kaspa' | 'nexa' | 'dynex' | 'nervos';
658
+ type INetwork = 'evm' | 'btc' | 'tbtc' | 'doge' | 'neurai' | 'ltc' | 'bch' | 'sol' | 'algo' | 'near' | 'stc' | 'cfx' | 'tron' | 'aptos' | 'xrp' | 'cosmos' | 'ada' | 'sui' | 'fil' | 'dot' | 'kaspa' | 'nexa' | 'dynex' | 'nervos' | 'scdo' | 'ton' | 'alph' | 'nostr';
659
659
  type CommonResponseParams = {
660
660
  path: string;
661
661
  network: INetwork;
@@ -672,6 +672,8 @@ type AllNetworkAddressParams = {
672
672
  type AllNetworkAddressPayload = {
673
673
  address: string;
674
674
  publicKey?: string;
675
+ pub?: string;
676
+ npub?: string;
675
677
  } | {
676
678
  addressParameters: CardanoAddressParameters;
677
679
  protocolMagic: number;
package/dist/index.js CHANGED
@@ -28062,7 +28062,7 @@ const networkConfigMap = {
28062
28062
  methodName: 'xrpGetAddress',
28063
28063
  },
28064
28064
  cosmos: {
28065
- methodName: 'cosmosGetAddress',
28065
+ methodName: 'cosmosGetPublicKey',
28066
28066
  getParams: (baseParams) => {
28067
28067
  const { path, prefix, showOnOneKey } = baseParams;
28068
28068
  return {
@@ -28099,6 +28099,14 @@ const networkConfigMap = {
28099
28099
  },
28100
28100
  sui: {
28101
28101
  methodName: 'suiGetAddress',
28102
+ dependOnMethodName: ['suiGetPublicKey'],
28103
+ getParams: (baseParams) => {
28104
+ const { path, showOnOneKey } = baseParams;
28105
+ return {
28106
+ path,
28107
+ showOnOneKey,
28108
+ };
28109
+ },
28102
28110
  },
28103
28111
  fil: {
28104
28112
  methodName: 'filecoinGetAddress',
@@ -28168,6 +28176,18 @@ const networkConfigMap = {
28168
28176
  };
28169
28177
  },
28170
28178
  },
28179
+ scdo: {
28180
+ methodName: 'scdoGetAddress',
28181
+ },
28182
+ ton: {
28183
+ methodName: 'tonGetAddress',
28184
+ },
28185
+ alph: {
28186
+ methodName: 'alephiumGetAddress',
28187
+ },
28188
+ nostr: {
28189
+ methodName: 'nostrGetPublicKey',
28190
+ },
28171
28191
  };
28172
28192
  class AllNetworkGetAddress extends BaseMethod {
28173
28193
  init() {
@@ -28184,7 +28204,7 @@ class AllNetworkGetAddress extends BaseMethod {
28184
28204
  });
28185
28205
  }
28186
28206
  generateMethodName({ network, payload, }) {
28187
- var _a, _b;
28207
+ var _a, _b, _c;
28188
28208
  const { name: networkName, coin } = networkAliases[network] || {
28189
28209
  name: network,
28190
28210
  coin: payload === null || payload === void 0 ? void 0 : payload.chainName,
@@ -28193,45 +28213,65 @@ class AllNetworkGetAddress extends BaseMethod {
28193
28213
  if (!config) {
28194
28214
  throw new Error(`Unsupported network: ${network}`);
28195
28215
  }
28216
+ const dependOnMethods = (_a = config.dependOnMethodName) === null || _a === void 0 ? void 0 : _a.map(dependOnMethodName => {
28217
+ var _a;
28218
+ return ({
28219
+ methodName: dependOnMethodName,
28220
+ params: (_a = config === null || config === void 0 ? void 0 : config.getParams) === null || _a === void 0 ? void 0 : _a.call(config, payload, coin, dependOnMethodName),
28221
+ });
28222
+ });
28196
28223
  return {
28197
28224
  methodName: config.methodName,
28198
- params: (_b = (_a = config === null || config === void 0 ? void 0 : config.getParams) === null || _a === void 0 ? void 0 : _a.call(config, payload, coin)) !== null && _b !== void 0 ? _b : payload,
28225
+ params: Object.assign(Object.assign({}, ((_c = (_b = config === null || config === void 0 ? void 0 : config.getParams) === null || _b === void 0 ? void 0 : _b.call(config, payload, coin, config.methodName)) !== null && _c !== void 0 ? _c : payload)), { originPayload: payload }),
28226
+ dependOnMethods,
28199
28227
  };
28200
28228
  }
28229
+ callMethod(methodName, params, baseParams) {
28230
+ var _a;
28231
+ return __awaiter(this, void 0, void 0, function* () {
28232
+ const method = findMethod({
28233
+ event: IFRAME.CALL,
28234
+ type: IFRAME.CALL,
28235
+ payload: Object.assign({ connectId: this.payload.connectId, deviceId: this.payload.deviceId, method: methodName }, params),
28236
+ });
28237
+ method.connector = this.connector;
28238
+ method.postMessage = this.postMessage;
28239
+ method.init();
28240
+ (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, this.device);
28241
+ let result;
28242
+ try {
28243
+ const response = yield method.run();
28244
+ result = Object.assign(Object.assign({}, baseParams), { success: true, error: response.error, payload: response });
28245
+ }
28246
+ catch (e) {
28247
+ const errorMessage = e instanceof Error ? handleHardwareError(e, this.device, method) : 'Unknown error';
28248
+ result = Object.assign(Object.assign({}, baseParams), { success: false, error: errorMessage });
28249
+ }
28250
+ return result;
28251
+ });
28252
+ }
28201
28253
  run() {
28202
28254
  var _a;
28203
28255
  return __awaiter(this, void 0, void 0, function* () {
28204
28256
  const responses = [];
28205
28257
  for (let i = 0; i < this.payload.bundle.length; i++) {
28206
28258
  const param = this.payload.bundle[i];
28207
- const { methodName, params } = this.generateMethodName({
28259
+ const { methodName, params, dependOnMethods } = this.generateMethodName({
28208
28260
  network: param.network,
28209
28261
  payload: param,
28210
28262
  });
28211
- const method = findMethod({
28212
- event: IFRAME.CALL,
28213
- type: IFRAME.CALL,
28214
- payload: Object.assign({ connectId: this.payload.connectId, deviceId: this.payload.deviceId, method: methodName }, params),
28215
- });
28216
- method.connector = this.connector;
28217
- method.postMessage = this.postMessage;
28218
- method.init();
28219
- (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, this.device);
28220
- const baseParams = {
28221
- network: param.network,
28222
- path: typeof param.path === 'string' ? param.path : serializedPath(param.path),
28223
- chainName: param.chainName,
28224
- prefix: param.prefix,
28225
- };
28226
- let result;
28227
- try {
28228
- const response = yield method.run();
28229
- result = Object.assign(Object.assign({}, baseParams), { success: true, error: response.error, payload: response });
28263
+ const dependOnMethodResults = [];
28264
+ for (const dependOnMethod of dependOnMethods !== null && dependOnMethods !== void 0 ? dependOnMethods : []) {
28265
+ const response = yield this.callMethod(dependOnMethod.methodName, dependOnMethod.params, param);
28266
+ dependOnMethodResults.push(response);
28230
28267
  }
28231
- catch (e) {
28232
- const errorMessage = e instanceof Error ? handleHardwareError(e, this.device, method) : 'Unknown error';
28233
- result = Object.assign(Object.assign({}, baseParams), { success: false, error: errorMessage });
28268
+ if (dependOnMethodResults.some(result => !result.success)) {
28269
+ responses.push(Object.assign(Object.assign({}, param), { success: false, error: (_a = dependOnMethodResults.find(result => !result.success)) === null || _a === void 0 ? void 0 : _a.error }));
28270
+ return Promise.resolve(responses);
28234
28271
  }
28272
+ const response = yield this.callMethod(methodName, params, param);
28273
+ const dependOnPayloads = dependOnMethodResults.reduce((acc, cur) => Object.assign(acc, lodash.get(cur, 'payload', {})), {});
28274
+ const result = Object.assign(Object.assign({}, response), { payload: Object.assign(Object.assign({}, response.payload), dependOnPayloads) });
28235
28275
  responses.push(result);
28236
28276
  this.postPreviousAddressMessage(result);
28237
28277
  }
@@ -1,7 +1,7 @@
1
1
  import type { CommonParams, Response } from '../params';
2
2
  import type { CardanoAddressParameters } from './cardano';
3
- export type INetwork = 'evm' | 'btc' | 'tbtc' | 'doge' | 'neurai' | 'ltc' | 'bch' | 'sol' | 'algo' | 'near' | 'stc' | 'cfx' | 'tron' | 'aptos' | 'xrp' | 'cosmos' | 'ada' | 'sui' | 'fil' | 'dot' | 'kaspa' | 'nexa' | 'dynex' | 'nervos';
4
- type CommonResponseParams = {
3
+ export type INetwork = 'evm' | 'btc' | 'tbtc' | 'doge' | 'neurai' | 'ltc' | 'bch' | 'sol' | 'algo' | 'near' | 'stc' | 'cfx' | 'tron' | 'aptos' | 'xrp' | 'cosmos' | 'ada' | 'sui' | 'fil' | 'dot' | 'kaspa' | 'nexa' | 'dynex' | 'nervos' | 'scdo' | 'ton' | 'alph' | 'nostr';
4
+ export type CommonResponseParams = {
5
5
  path: string;
6
6
  network: INetwork;
7
7
  chainName?: string;
@@ -17,6 +17,8 @@ export type AllNetworkAddressParams = {
17
17
  type AllNetworkAddressPayload = {
18
18
  address: string;
19
19
  publicKey?: string;
20
+ pub?: string;
21
+ npub?: string;
20
22
  } | {
21
23
  addressParameters: CardanoAddressParameters;
22
24
  protocolMagic: number;
@@ -1 +1 @@
1
- {"version":3,"file":"allNetworkGetAddress.d.ts","sourceRoot":"","sources":["../../../src/types/api/allNetworkGetAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAE1D,MAAM,MAAM,QAAQ,GAChB,KAAK,GAEL,KAAK,GACL,MAAM,GACN,MAAM,GACN,QAAQ,GACR,KAAK,GACL,KAAK,GAEL,KAAK,GACL,MAAM,GACN,MAAM,GACN,KAAK,GACL,KAAK,GACL,MAAM,GACN,OAAO,GACP,KAAK,GACL,QAAQ,GACR,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,OAAO,GACP,MAAM,GACN,OAAO,GACP,QAAQ,CAAC;AAEb,KAAK,oBAAoB,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;IACl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,EAAE,CAAC;CACnC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG,0BAA0B,GAChD,QAAQ,CAAC,iBAAiB,EAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"allNetworkGetAddress.d.ts","sourceRoot":"","sources":["../../../src/types/api/allNetworkGetAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAE1D,MAAM,MAAM,QAAQ,GAChB,KAAK,GAEL,KAAK,GACL,MAAM,GACN,MAAM,GACN,QAAQ,GACR,KAAK,GACL,KAAK,GAEL,KAAK,GACL,MAAM,GACN,MAAM,GACN,KAAK,GACL,KAAK,GACL,MAAM,GACN,OAAO,GACP,KAAK,GACL,QAAQ,GACR,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,OAAO,GACP,MAAM,GACN,OAAO,GACP,QAAQ,GACR,MAAM,GACN,KAAK,GACL,MAAM,GACN,OAAO,CAAC;AAEZ,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,QAAQ,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,OAAO,EAAE,QAAQ,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,KAAK,wBAAwB,GACzB;IACE,OAAO,EAAE,MAAM,CAAC;IAChB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"1.0.12-alpha.1",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-shared": "^1.0.12-alpha.0",
29
- "@onekeyfe/hd-transport": "^1.0.12-alpha.0",
28
+ "@onekeyfe/hd-shared": "^1.0.12-alpha.1",
29
+ "@onekeyfe/hd-transport": "^1.0.12-alpha.1",
30
30
  "axios": "^0.27.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "bytebuffer": "^5.0.1",
@@ -44,5 +44,5 @@
44
44
  "@types/semver": "^7.3.9",
45
45
  "ripple-keypairs": "^1.1.4"
46
46
  },
47
- "gitHead": "4707d9ff824c0201684bb67b1053d907dabcd7e0"
47
+ "gitHead": "dedf68e03978e46ef921e1d71fd06fc323dfab26"
48
48
  }
@@ -1,5 +1,6 @@
1
1
  import semver from 'semver';
2
2
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
+ import { get } from 'lodash';
3
4
  import { UI_REQUEST } from '../../constants/ui-request';
4
5
  import { serializedPath } from '../helpers/pathUtils';
5
6
  import { BaseMethod } from '../BaseMethod';
@@ -9,6 +10,7 @@ import { CoreApi } from '../../types';
9
10
  import type {
10
11
  AllNetworkAddress,
11
12
  AllNetworkAddressParams,
13
+ CommonResponseParams,
12
14
  INetwork,
13
15
  } from '../../types/api/allNetworkGetAddress';
14
16
  import { findMethod } from '../utils';
@@ -21,7 +23,8 @@ const Mainnet = 'mainnet';
21
23
 
22
24
  type NetworkConfig = {
23
25
  methodName: keyof CoreApi;
24
- getParams?: (baseParams: AllNetworkAddressParams, chainName?: string) => any;
26
+ getParams?: (baseParams: AllNetworkAddressParams, chainName?: string, methodName?: string) => any;
27
+ dependOnMethodName?: (keyof CoreApi)[];
25
28
  };
26
29
 
27
30
  type INetworkReal = Exclude<INetwork, 'tbtc' | 'bch' | 'doge' | 'ltc' | 'neurai'>;
@@ -96,7 +99,7 @@ const networkConfigMap: NetworkConfigMap = {
96
99
  methodName: 'xrpGetAddress',
97
100
  },
98
101
  cosmos: {
99
- methodName: 'cosmosGetAddress',
102
+ methodName: 'cosmosGetPublicKey',
100
103
  getParams: (baseParams: AllNetworkAddressParams) => {
101
104
  const { path, prefix, showOnOneKey } = baseParams;
102
105
  return {
@@ -138,6 +141,14 @@ const networkConfigMap: NetworkConfigMap = {
138
141
  },
139
142
  sui: {
140
143
  methodName: 'suiGetAddress',
144
+ dependOnMethodName: ['suiGetPublicKey'],
145
+ getParams: (baseParams: AllNetworkAddressParams) => {
146
+ const { path, showOnOneKey } = baseParams;
147
+ return {
148
+ path,
149
+ showOnOneKey,
150
+ };
151
+ },
141
152
  },
142
153
  fil: {
143
154
  methodName: 'filecoinGetAddress',
@@ -207,6 +218,18 @@ const networkConfigMap: NetworkConfigMap = {
207
218
  };
208
219
  },
209
220
  },
221
+ scdo: {
222
+ methodName: 'scdoGetAddress',
223
+ },
224
+ ton: {
225
+ methodName: 'tonGetAddress',
226
+ },
227
+ alph: {
228
+ methodName: 'alephiumGetAddress',
229
+ },
230
+ nostr: {
231
+ methodName: 'nostrGetPublicKey',
232
+ },
210
233
  };
211
234
 
212
235
  export default class AllNetworkGetAddress extends BaseMethod<
@@ -243,7 +266,13 @@ export default class AllNetworkGetAddress extends BaseMethod<
243
266
  payload: AllNetworkAddressParams;
244
267
  }): {
245
268
  methodName: keyof CoreApi;
246
- params: Parameters<CoreApi[keyof CoreApi]>[0];
269
+ params: Parameters<CoreApi[keyof CoreApi]>[0] & { originPayload: AllNetworkAddressParams };
270
+ dependOnMethods:
271
+ | {
272
+ methodName: keyof CoreApi;
273
+ params: Parameters<CoreApi[keyof CoreApi]>[0];
274
+ }[]
275
+ | undefined;
247
276
  } {
248
277
  const { name: networkName, coin } = networkAliases[network] || {
249
278
  name: network,
@@ -254,64 +283,104 @@ export default class AllNetworkGetAddress extends BaseMethod<
254
283
  throw new Error(`Unsupported network: ${network}`);
255
284
  }
256
285
 
286
+ const dependOnMethods = config.dependOnMethodName?.map(dependOnMethodName => ({
287
+ methodName: dependOnMethodName,
288
+ params: config?.getParams?.(payload, coin, dependOnMethodName),
289
+ }));
290
+
257
291
  return {
258
292
  methodName: config.methodName,
259
- params: config?.getParams?.(payload, coin) ?? payload,
293
+ params: {
294
+ ...(config?.getParams?.(payload, coin, config.methodName) ?? payload),
295
+ originPayload: payload,
296
+ },
297
+ dependOnMethods,
260
298
  };
261
299
  }
262
300
 
301
+ async callMethod(methodName: keyof CoreApi, params: any, baseParams: CommonResponseParams) {
302
+ const method: BaseMethod = findMethod({
303
+ event: IFRAME.CALL,
304
+ type: IFRAME.CALL,
305
+ payload: {
306
+ connectId: this.payload.connectId,
307
+ deviceId: this.payload.deviceId,
308
+ method: methodName,
309
+ ...params,
310
+ },
311
+ });
312
+
313
+ method.connector = this.connector;
314
+ method.postMessage = this.postMessage;
315
+ method.init();
316
+ method.setDevice?.(this.device);
317
+
318
+ let result: AllNetworkAddress;
319
+ try {
320
+ const response = await method.run();
321
+ result = {
322
+ ...baseParams,
323
+ success: true,
324
+ error: response.error,
325
+ payload: response,
326
+ };
327
+ } catch (e: any) {
328
+ const errorMessage =
329
+ e instanceof Error ? handleHardwareError(e, this.device, method) : 'Unknown error';
330
+
331
+ result = {
332
+ ...baseParams,
333
+ success: false,
334
+ error: errorMessage,
335
+ };
336
+ }
337
+
338
+ return result;
339
+ }
340
+
263
341
  async run() {
264
342
  const responses: AllNetworkAddress[] = [];
265
343
  for (let i = 0; i < this.payload.bundle.length; i++) {
266
344
  const param = this.payload.bundle[i];
267
- const { methodName, params } = this.generateMethodName({
345
+ const { methodName, params, dependOnMethods } = this.generateMethodName({
268
346
  network: param.network as INetwork,
269
347
  payload: param,
270
348
  });
271
349
 
272
- const method: BaseMethod = findMethod({
273
- event: IFRAME.CALL,
274
- type: IFRAME.CALL,
275
- payload: {
276
- connectId: this.payload.connectId,
277
- deviceId: this.payload.deviceId,
278
- method: methodName,
279
- ...params,
280
- },
281
- });
282
-
283
- method.connector = this.connector;
284
- method.postMessage = this.postMessage;
285
- method.init();
286
- method.setDevice?.(this.device);
287
-
288
- const baseParams = {
289
- network: param.network,
290
- path: typeof param.path === 'string' ? param.path : serializedPath(param.path),
291
- chainName: param.chainName,
292
- prefix: param.prefix,
293
- };
350
+ // run depend on methods
351
+ const dependOnMethodResults: AllNetworkAddress[] = [];
352
+ for (const dependOnMethod of dependOnMethods ?? []) {
353
+ const response = await this.callMethod(
354
+ dependOnMethod.methodName,
355
+ dependOnMethod.params,
356
+ param
357
+ );
358
+ dependOnMethodResults.push(response);
359
+ }
294
360
 
295
- let result: AllNetworkAddress;
296
- try {
297
- const response = await method.run();
298
- result = {
299
- ...baseParams,
300
- success: true,
301
- error: response.error,
302
- payload: response,
303
- };
304
- } catch (e: any) {
305
- const errorMessage =
306
- e instanceof Error ? handleHardwareError(e, this.device, method) : 'Unknown error';
307
-
308
- result = {
309
- ...baseParams,
361
+ // if any depend on method failed, return the error
362
+ if (dependOnMethodResults.some(result => !result.success)) {
363
+ responses.push({
364
+ ...param,
310
365
  success: false,
311
- error: errorMessage,
312
- };
366
+ error: dependOnMethodResults.find(result => !result.success)?.error,
367
+ });
368
+ return Promise.resolve(responses);
313
369
  }
314
370
 
371
+ // call method
372
+ const response = await this.callMethod(methodName, params, param);
373
+
374
+ const dependOnPayloads = dependOnMethodResults.reduce(
375
+ (acc, cur) => Object.assign(acc, get(cur, 'payload', {})),
376
+ {}
377
+ );
378
+
379
+ const result: AllNetworkAddress = {
380
+ ...response,
381
+ // @ts-expect-error
382
+ payload: { ...response.payload, ...dependOnPayloads },
383
+ };
315
384
  responses.push(result);
316
385
  this.postPreviousAddressMessage(result);
317
386
  }
@@ -27,9 +27,13 @@ export type INetwork =
27
27
  | 'kaspa'
28
28
  | 'nexa'
29
29
  | 'dynex'
30
- | 'nervos';
30
+ | 'nervos'
31
+ | 'scdo'
32
+ | 'ton'
33
+ | 'alph'
34
+ | 'nostr';
31
35
 
32
- type CommonResponseParams = {
36
+ export type CommonResponseParams = {
33
37
  path: string;
34
38
  network: INetwork;
35
39
  chainName?: string;
@@ -48,6 +52,9 @@ type AllNetworkAddressPayload =
48
52
  | {
49
53
  address: string;
50
54
  publicKey?: string;
55
+ pub?: string;
56
+ // Nostr public key (bech32)
57
+ npub?: string;
51
58
  }
52
59
  | {
53
60
  // Cardano