@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.
- package/__tests__/benfen.test.ts +16 -0
- package/__tests__/checkBootloaderReleast.test.js +7 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/benfen/normalize.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -9
- package/dist/types/api/benfenSignTransaction.d.ts +1 -0
- package/dist/types/api/benfenSignTransaction.d.ts.map +1 -1
- package/jest.config.js +1 -0
- package/package.json +4 -4
- package/src/api/benfen/BenfenSignTransaction.ts +4 -5
- package/src/api/benfen/normalize.ts +6 -0
- package/src/types/api/benfenSignTransaction.ts +1 -0
|
@@ -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
|
-
|
|
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;
|
|
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;
|
|
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:
|
|
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
|
-
|
|
35621
|
-
|
|
35622
|
-
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.0.
|
|
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.
|
|
29
|
-
"@onekeyfe/hd-transport": "^1.0.
|
|
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": "
|
|
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:
|
|
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
|
-
|
|
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)) {
|