@onekeyfe/hd-core 1.0.15-alpha.1 → 1.0.16-alpha.0

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.
@@ -0,0 +1,16 @@
1
+ import { publicKeyToAddress, hex2BfcAddress } from '../src/api/benfen/normalize';
2
+
3
+ describe('Benfen Address Normalization', () => {
4
+ it('publicKeyToBFCAddress', () => {
5
+ // Test case with a known public key and its expected address
6
+ const publicKey = '6e9c9ef745cc3a250168db15526d18075dc52849d49f8a6ea5477c1c264b4848';
7
+ const expectedHexAddress = '0xb4ced58018b75d7ba72a10fa97c09b7bf66533ff104bf9db1bfdb004b17d8eaa';
8
+ const expectedAddress =
9
+ 'BFCb4ced58018b75d7ba72a10fa97c09b7bf66533ff104bf9db1bfdb004b17d8eaa2e35';
10
+
11
+ const hexAddress = publicKeyToAddress(publicKey);
12
+ const bfcAddress = hex2BfcAddress(hexAddress);
13
+ expect(hexAddress).toBe(expectedHexAddress);
14
+ expect(bfcAddress).toBe(expectedAddress);
15
+ });
16
+ });
@@ -1,5 +1,11 @@
1
1
  /* eslint-disable @typescript-eslint/no-var-requires */
2
- const { shouldUpdateBootloaderForClassicAndMini } = require('../src/api/firmware/bootloaderHelper');
2
+ import { shouldUpdateBootloaderForClassicAndMini } from '../src/api/firmware/bootloaderHelper';
3
+
4
+ // Add mock for config module
5
+ jest.mock('../src/data/config', () => ({
6
+ getSDKVersion: () => '1.0.0',
7
+ DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
8
+ }));
3
9
 
4
10
  const fixtures = [
5
11
  {
@@ -1 +1 @@
1
- {"version":3,"file":"BenfenSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/api/benfen/BenfenSignTransaction.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,cAAc,EAAe,MAAM,wBAAwB,CAAC;AAK9F,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,UAAU,CAAC,YAAY,CAAC;IACzE,IAAI;IA+BJ,aAAa,SAAQ;IAErB,gBAAgB,cACH,SAAS,OACf,qBAAqB,gBAAgB,CAAC,GAAG,qBAAqB,iBAAiB,CAAC,QAC/E,MAAM,sBAEX,QAAQ,cAAc,CAAC,CA+BxB;IAEI,GAAG;CAkBV"}
1
+ {"version":3,"file":"BenfenSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/api/benfen/BenfenSignTransaction.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,cAAc,EAAe,MAAM,wBAAwB,CAAC;AAK9F,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,UAAU,CAAC,YAAY,CAAC;IACzE,IAAI;IA8BJ,aAAa,SAAQ;IAErB,gBAAgB,cACH,SAAS,OACf,qBAAqB,gBAAgB,CAAC,GAAG,qBAAqB,iBAAiB,CAAC,QAC/E,MAAM,sBAEX,QAAQ,cAAc,CAAC,CA+BxB;IAEI,GAAG;CAkBV"}
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/api/benfen/normalize.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,eAAO,MAAM,wBAAwB;;CAEpC,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,MAAM,CAMhF;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,UAQnD;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAezD"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/api/benfen/normalize.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,eAAO,MAAM,wBAAwB;;CAEpC,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,MAAM,CAMhF;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,UAQnD;AAQD,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAezD"}
package/dist/index.d.ts CHANGED
@@ -2138,6 +2138,7 @@ type BenfenSignedTx = {
2138
2138
  } & AptosSignedTx$1;
2139
2139
  type BenfenSignTransactionParams = {
2140
2140
  path: string | number[];
2141
+ coinType?: string;
2141
2142
  rawTx?: string;
2142
2143
  };
2143
2144
  declare function benfenSignTransaction(connectId: string, deviceId: string, params: CommonParams & BenfenSignTransactionParams): Response<BenfenSignedTx>;
package/dist/index.js CHANGED
@@ -35613,18 +35613,13 @@ class BenfenSignTransaction extends BaseMethod {
35613
35613
  validateParams(this.payload, [
35614
35614
  { name: 'path', required: true },
35615
35615
  { name: 'rawTx', type: 'hexString', required: true },
35616
- { name: 'coinType', type: 'string', required: true },
35616
+ { name: 'coinType', type: 'string', required: false },
35617
35617
  ]);
35618
35618
  const { path, rawTx, coinType } = this.payload;
35619
35619
  const addressN = validatePath(path, 3);
35620
- const coinTypeHex = coinType.startsWith('0x')
35621
- ? coinType.slice(2)
35622
- : Buffer.from(coinType).toString('hex');
35623
- this.params = {
35624
- address_n: addressN,
35625
- raw_tx: formatAnyHex(rawTx),
35626
- coin_type: formatAnyHex(coinTypeHex),
35627
- };
35620
+ this.params = Object.assign({ address_n: addressN, raw_tx: formatAnyHex(rawTx) }, (coinType && {
35621
+ coin_type: formatAnyHex(Buffer.from(coinType).toString('hex')),
35622
+ }));
35628
35623
  }
35629
35624
  run() {
35630
35625
  return __awaiter(this, void 0, void 0, function* () {
@@ -6,6 +6,7 @@ export type BenfenSignedTx = {
6
6
  } & HardwareAptosSignedTx;
7
7
  export type BenfenSignTransactionParams = {
8
8
  path: string | number[];
9
+ coinType?: string;
9
10
  rawTx?: string;
10
11
  };
11
12
  export declare function benfenSignTransaction(connectId: string, deviceId: string, params: CommonParams & BenfenSignTransactionParams): Response<BenfenSignedTx>;
@@ -1 +1 @@
1
- {"version":3,"file":"benfenSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/types/api/benfenSignTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,qBAAqB,CAAC;AAE1B,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG,2BAA2B,GACjD,QAAQ,CAAC,cAAc,CAAC,CAAC"}
1
+ {"version":3,"file":"benfenSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/types/api/benfenSignTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,qBAAqB,CAAC;AAE1B,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAC3C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG,2BAA2B,GACjD,QAAQ,CAAC,cAAc,CAAC,CAAC"}
package/jest.config.js CHANGED
@@ -2,4 +2,5 @@ module.exports = {
2
2
  preset: '../../jest.config.js',
3
3
  testEnvironment: 'node',
4
4
  modulePathIgnorePatterns: ['node_modules', '<rootDir>/lib', '<rootDir>/libDev'],
5
+ collectCoverage: true,
5
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.0.15-alpha.1",
3
+ "version": "1.0.16-alpha.0",
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.15-alpha.1",
29
- "@onekeyfe/hd-transport": "^1.0.15-alpha.1",
28
+ "@onekeyfe/hd-shared": "^1.0.16-alpha.0",
29
+ "@onekeyfe/hd-transport": "^1.0.16-alpha.0",
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": "a9109a126624f719af1534ad0f1d15314a80ce13"
47
+ "gitHead": "233ae26c003f089644e203620fcf53210385f591"
48
48
  }
@@ -16,19 +16,18 @@ export default class BenfenSignTransaction extends BaseMethod<BenfenSignTx> {
16
16
  validateParams(this.payload, [
17
17
  { name: 'path', required: true },
18
18
  { name: 'rawTx', type: 'hexString', required: true },
19
- { name: 'coinType', type: 'string', required: true },
19
+ { name: 'coinType', type: 'string', required: false },
20
20
  ]);
21
21
 
22
22
  const { path, rawTx, coinType } = this.payload;
23
23
  const addressN = validatePath(path, 3);
24
- const coinTypeHex = coinType.startsWith('0x')
25
- ? coinType.slice(2)
26
- : Buffer.from(coinType).toString('hex');
27
24
 
28
25
  this.params = {
29
26
  address_n: addressN,
30
27
  raw_tx: formatAnyHex(rawTx),
31
- coin_type: formatAnyHex(coinTypeHex),
28
+ ...(coinType && {
29
+ coin_type: formatAnyHex(Buffer.from(coinType).toString('hex')),
30
+ }),
32
31
  };
33
32
  }
34
33
 
@@ -27,6 +27,12 @@ export function publicKeyToAddress(publicKey: string) {
27
27
  );
28
28
  }
29
29
 
30
+ /**
31
+ * 将十六进制地址转换为 BFC 格式地址
32
+ * @param hexAddress - 输入的十六进制地址(可以带有0x前缀)
33
+ * @returns BFC格式的地址,格式为:BFC + 64位地址 + 4位校验和
34
+ * @throws {Error} 当输入地址格式无效时
35
+ */
30
36
  export function hex2BfcAddress(hexAddress: string): string {
31
37
  // 如果已经是BFC格式,直接返回
32
38
  if (/^BFC/i.test(hexAddress)) {
@@ -8,6 +8,7 @@ export type BenfenSignedTx = {
8
8
 
9
9
  export type BenfenSignTransactionParams = {
10
10
  path: string | number[];
11
+ coinType?: string;
11
12
  rawTx?: string;
12
13
  };
13
14