@onekeyfe/hd-core 0.2.44 → 0.2.46
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/dist/api/cardano/CardanoGetAddress.d.ts.map +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +0 -1
- package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
- package/dist/api/sui/normalize.d.ts +9 -0
- package/dist/api/sui/normalize.d.ts.map +1 -0
- package/dist/index.js +34 -17
- package/package.json +4 -4
- package/src/api/cardano/CardanoGetAddress.ts +6 -3
- package/src/api/sui/SuiGetAddress.ts +4 -15
- package/src/api/sui/SuiGetPublicKey.ts +2 -2
- package/src/api/sui/SuiSignTransaction.ts +2 -2
- package/src/api/sui/normalize.ts +28 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CardanoGetAddress.d.ts","sourceRoot":"","sources":["../../../src/api/cardano/CardanoGetAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAU3C,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"CardanoGetAddress.d.ts","sourceRoot":"","sources":["../../../src/api/cardano/CardanoGetAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAU3C,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAG5F,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU,CAAC,uBAAuB,EAAE,CAAC;IAClF,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,IAAI;IAqCJ,eAAe;;;;;;;;IAWT,GAAG;CAmEV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuiGetAddress.d.ts","sourceRoot":"","sources":["../../../src/api/sui/SuiGetAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"SuiGetAddress.d.ts","sourceRoot":"","sources":["../../../src/api/sui/SuiGetAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAIhF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAuB,MAAM,aAAa,CAAC;AAI9D,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU,CAAC,qBAAqB,EAAE,CAAC;IAC5E,SAAS,UAAS;IAElB,aAAa,UAAS;IAEtB,IAAI;IAiCJ,eAAe;;;;;;;;IAWT,GAAG;CAkCV"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const SUI_ADDRESS_LENGTH = 32;
|
|
2
|
+
export declare const PUBLIC_KEY_SIZE = 32;
|
|
3
|
+
export declare const SIGNATURE_SCHEME_TO_FLAG: {
|
|
4
|
+
ED25519: number;
|
|
5
|
+
Secp256k1: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function normalizeSuiAddress(value: string, forceAdd0x?: boolean): string;
|
|
8
|
+
export declare function publicKeyToAddress(publicKey: string): string;
|
|
9
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/api/sui/normalize.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,eAAO,MAAM,wBAAwB;;;CAGpC,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,MAAM,CAM7E;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,UAQnD"}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var sha256 = require('@noble/hashes/sha256');
|
|
|
14
14
|
var JSZip = require('jszip');
|
|
15
15
|
var sha3 = require('@noble/hashes/sha3');
|
|
16
16
|
var rippleKeypairs = require('ripple-keypairs');
|
|
17
|
+
var blake2b = require('@noble/hashes/blake2b');
|
|
17
18
|
|
|
18
19
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
20
|
|
|
@@ -17100,6 +17101,26 @@ class XrpGetAddress extends BaseMethod {
|
|
|
17100
17101
|
}
|
|
17101
17102
|
}
|
|
17102
17103
|
|
|
17104
|
+
const SUI_ADDRESS_LENGTH = 32;
|
|
17105
|
+
const PUBLIC_KEY_SIZE = 32;
|
|
17106
|
+
const SIGNATURE_SCHEME_TO_FLAG = {
|
|
17107
|
+
ED25519: 0x00,
|
|
17108
|
+
Secp256k1: 0x01,
|
|
17109
|
+
};
|
|
17110
|
+
function normalizeSuiAddress(value, forceAdd0x = false) {
|
|
17111
|
+
let address = value.toLowerCase();
|
|
17112
|
+
if (!forceAdd0x && address.startsWith('0x')) {
|
|
17113
|
+
address = address.slice(2);
|
|
17114
|
+
}
|
|
17115
|
+
return `0x${address.padStart(SUI_ADDRESS_LENGTH * 2, '0')}`.toLowerCase();
|
|
17116
|
+
}
|
|
17117
|
+
function publicKeyToAddress(publicKey) {
|
|
17118
|
+
const tmp = new Uint8Array(PUBLIC_KEY_SIZE + 1);
|
|
17119
|
+
tmp.set([SIGNATURE_SCHEME_TO_FLAG.ED25519]);
|
|
17120
|
+
tmp.set(utils.hexToBytes(publicKey), 1);
|
|
17121
|
+
return normalizeSuiAddress(utils.bytesToHex(blake2b.blake2b(tmp, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2));
|
|
17122
|
+
}
|
|
17123
|
+
|
|
17103
17124
|
class SuiGetAddress extends BaseMethod {
|
|
17104
17125
|
constructor() {
|
|
17105
17126
|
super(...arguments);
|
|
@@ -17131,19 +17152,13 @@ class SuiGetAddress extends BaseMethod {
|
|
|
17131
17152
|
});
|
|
17132
17153
|
});
|
|
17133
17154
|
}
|
|
17134
|
-
publicKeyToAddress(publicKey) {
|
|
17135
|
-
const hash = sha3.sha3_256.create();
|
|
17136
|
-
hash.update('\x00');
|
|
17137
|
-
hash.update(hexToBytes(publicKey));
|
|
17138
|
-
return `0x${utils.bytesToHex(hash.digest().slice(0, 20))}`;
|
|
17139
|
-
}
|
|
17140
17155
|
getVersionRange() {
|
|
17141
17156
|
return {
|
|
17142
17157
|
model_mini: {
|
|
17143
|
-
min: '2.
|
|
17158
|
+
min: '2.12.0',
|
|
17144
17159
|
},
|
|
17145
17160
|
model_touch: {
|
|
17146
|
-
min: '3.
|
|
17161
|
+
min: '4.3.0',
|
|
17147
17162
|
},
|
|
17148
17163
|
};
|
|
17149
17164
|
}
|
|
@@ -17158,7 +17173,7 @@ class SuiGetAddress extends BaseMethod {
|
|
|
17158
17173
|
const result = res.message.public_keys.map((publicKey, index) => ({
|
|
17159
17174
|
path: serializedPath(this.params[index].address_n),
|
|
17160
17175
|
publicKey,
|
|
17161
|
-
address:
|
|
17176
|
+
address: publicKeyToAddress(publicKey),
|
|
17162
17177
|
}));
|
|
17163
17178
|
return Promise.resolve(result);
|
|
17164
17179
|
}
|
|
@@ -17209,10 +17224,10 @@ class SuiGetPublicKey extends BaseMethod {
|
|
|
17209
17224
|
getVersionRange() {
|
|
17210
17225
|
return {
|
|
17211
17226
|
model_mini: {
|
|
17212
|
-
min: '2.
|
|
17227
|
+
min: '2.12.0',
|
|
17213
17228
|
},
|
|
17214
17229
|
model_touch: {
|
|
17215
|
-
min: '3.
|
|
17230
|
+
min: '4.3.0',
|
|
17216
17231
|
},
|
|
17217
17232
|
};
|
|
17218
17233
|
}
|
|
@@ -17249,10 +17264,10 @@ class SuiSignTransaction extends BaseMethod {
|
|
|
17249
17264
|
getVersionRange() {
|
|
17250
17265
|
return {
|
|
17251
17266
|
model_mini: {
|
|
17252
|
-
min: '2.
|
|
17267
|
+
min: '2.12.0',
|
|
17253
17268
|
},
|
|
17254
17269
|
model_touch: {
|
|
17255
|
-
min: '3.
|
|
17270
|
+
min: '4.3.0',
|
|
17256
17271
|
},
|
|
17257
17272
|
};
|
|
17258
17273
|
}
|
|
@@ -17347,11 +17362,13 @@ const modifyAddressParametersForBackwardsCompatibility = (address_parameters) =>
|
|
|
17347
17362
|
|
|
17348
17363
|
class CardanoGetAddress extends BaseMethod {
|
|
17349
17364
|
init() {
|
|
17350
|
-
var _a, _b;
|
|
17365
|
+
var _a, _b, _c;
|
|
17351
17366
|
this.checkDeviceId = true;
|
|
17352
17367
|
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
17353
17368
|
this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
|
|
17354
|
-
this.isCheck =
|
|
17369
|
+
this.isCheck = this.hasBundle
|
|
17370
|
+
? !!((_b = this.payload) === null || _b === void 0 ? void 0 : _b.bundle.every((i) => !!i.isCheck))
|
|
17371
|
+
: !!((_c = this.payload) === null || _c === void 0 ? void 0 : _c.isCheck);
|
|
17355
17372
|
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
17356
17373
|
this.params = payload.bundle.map((batch) => {
|
|
17357
17374
|
validateParams(batch, [
|
|
@@ -17403,7 +17420,7 @@ class CardanoGetAddress extends BaseMethod {
|
|
|
17403
17420
|
const publicKeyRes = yield this.device.commands.typedCall('CardanoGetPublicKey', 'CardanoPublicKey', {
|
|
17404
17421
|
address_n: address_parameters.address_n.slice(0, 3),
|
|
17405
17422
|
derivation_type,
|
|
17406
|
-
show_display,
|
|
17423
|
+
show_display: false,
|
|
17407
17424
|
});
|
|
17408
17425
|
xpub = publicKeyRes.message.xpub;
|
|
17409
17426
|
const stakeAddressRes = yield this.device.commands.typedCall('CardanoGetAddress', 'CardanoAddress', {
|
|
@@ -17415,7 +17432,7 @@ class CardanoGetAddress extends BaseMethod {
|
|
|
17415
17432
|
protocol_magic,
|
|
17416
17433
|
network_id,
|
|
17417
17434
|
derivation_type,
|
|
17418
|
-
show_display,
|
|
17435
|
+
show_display: false,
|
|
17419
17436
|
});
|
|
17420
17437
|
stakeAddress = stakeAddressRes.message.address;
|
|
17421
17438
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.46",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@onekeyfe/hd-shared": "^0.2.
|
|
28
|
-
"@onekeyfe/hd-transport": "^0.2.
|
|
27
|
+
"@onekeyfe/hd-shared": "^0.2.46",
|
|
28
|
+
"@onekeyfe/hd-transport": "^0.2.46",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"bignumber.js": "^9.0.2",
|
|
31
31
|
"bytebuffer": "^5.0.1",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"@types/semver": "^7.3.9",
|
|
44
44
|
"ripple-keypairs": "^1.1.4"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "14a5773bffe764d0de7edc505e145c7670be0fcb"
|
|
47
47
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from './helper/addressParameters';
|
|
10
10
|
import { serializedPath } from '../helpers/pathUtils';
|
|
11
11
|
import { CardanoGetAddressParams, CardanoAddress } from '../../types/api/cardanoGetAddress';
|
|
12
|
+
import { CardanoGetAddressMethodParams } from '../../types';
|
|
12
13
|
|
|
13
14
|
export default class CardanoGetAddress extends BaseMethod<CardanoGetAddressParams[]> {
|
|
14
15
|
hasBundle?: boolean;
|
|
@@ -20,7 +21,9 @@ export default class CardanoGetAddress extends BaseMethod<CardanoGetAddressParam
|
|
|
20
21
|
this.notAllowDeviceMode = [...this.notAllowDeviceMode, UI_REQUEST.INITIALIZE];
|
|
21
22
|
|
|
22
23
|
this.hasBundle = !!this.payload?.bundle;
|
|
23
|
-
this.isCheck =
|
|
24
|
+
this.isCheck = this.hasBundle
|
|
25
|
+
? !!this.payload?.bundle.every((i: CardanoGetAddressMethodParams) => !!i.isCheck)
|
|
26
|
+
: !!this.payload?.isCheck;
|
|
24
27
|
const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
|
|
25
28
|
|
|
26
29
|
this.params = payload.bundle.map((batch: any) => {
|
|
@@ -84,7 +87,7 @@ export default class CardanoGetAddress extends BaseMethod<CardanoGetAddressParam
|
|
|
84
87
|
{
|
|
85
88
|
address_n: address_parameters.address_n.slice(0, 3),
|
|
86
89
|
derivation_type,
|
|
87
|
-
show_display,
|
|
90
|
+
show_display: false,
|
|
88
91
|
}
|
|
89
92
|
);
|
|
90
93
|
xpub = publicKeyRes.message.xpub;
|
|
@@ -101,7 +104,7 @@ export default class CardanoGetAddress extends BaseMethod<CardanoGetAddressParam
|
|
|
101
104
|
protocol_magic,
|
|
102
105
|
network_id,
|
|
103
106
|
derivation_type,
|
|
104
|
-
show_display,
|
|
107
|
+
show_display: false,
|
|
105
108
|
}
|
|
106
109
|
);
|
|
107
110
|
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { SuiGetAddress as HardwareSuiGetAddress } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
|
-
import { sha3_256 } from '@noble/hashes/sha3';
|
|
4
|
-
import { bytesToHex } from '@noble/hashes/utils';
|
|
5
3
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
6
4
|
import { serializedPath, validatePath } from '../helpers/pathUtils';
|
|
7
5
|
import { BaseMethod } from '../BaseMethod';
|
|
8
6
|
import { validateParams } from '../helpers/paramsValidator';
|
|
9
7
|
import { SuiAddress, SuiGetAddressParams } from '../../types';
|
|
10
8
|
import { supportBatchPublicKey } from '../../utils/deviceFeaturesUtils';
|
|
11
|
-
import {
|
|
9
|
+
import { publicKeyToAddress } from './normalize';
|
|
12
10
|
|
|
13
11
|
export default class SuiGetAddress extends BaseMethod<HardwareSuiGetAddress[]> {
|
|
14
12
|
hasBundle = false;
|
|
@@ -48,22 +46,13 @@ export default class SuiGetAddress extends BaseMethod<HardwareSuiGetAddress[]> {
|
|
|
48
46
|
});
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
publicKeyToAddress(publicKey: string) {
|
|
52
|
-
const hash = sha3_256.create();
|
|
53
|
-
// Ed25519
|
|
54
|
-
hash.update('\x00');
|
|
55
|
-
// hash.update('\x01'); Secp256k1
|
|
56
|
-
hash.update(hexToBytes(publicKey));
|
|
57
|
-
return `0x${bytesToHex(hash.digest().slice(0, 20))}`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
49
|
getVersionRange() {
|
|
61
50
|
return {
|
|
62
51
|
model_mini: {
|
|
63
|
-
min: '2.
|
|
52
|
+
min: '2.12.0',
|
|
64
53
|
},
|
|
65
54
|
model_touch: {
|
|
66
|
-
min: '3.
|
|
55
|
+
min: '4.3.0',
|
|
67
56
|
},
|
|
68
57
|
};
|
|
69
58
|
}
|
|
@@ -77,7 +66,7 @@ export default class SuiGetAddress extends BaseMethod<HardwareSuiGetAddress[]> {
|
|
|
77
66
|
const result = res.message.public_keys.map((publicKey: string, index: number) => ({
|
|
78
67
|
path: serializedPath((this.params as unknown as any[])[index].address_n),
|
|
79
68
|
publicKey,
|
|
80
|
-
address:
|
|
69
|
+
address: publicKeyToAddress(publicKey),
|
|
81
70
|
}));
|
|
82
71
|
return Promise.resolve(result);
|
|
83
72
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
|
|
2
|
+
import { blake2b } from '@noble/hashes/blake2b';
|
|
3
|
+
|
|
4
|
+
export const SUI_ADDRESS_LENGTH = 32;
|
|
5
|
+
export const PUBLIC_KEY_SIZE = 32;
|
|
6
|
+
|
|
7
|
+
export const SIGNATURE_SCHEME_TO_FLAG = {
|
|
8
|
+
ED25519: 0x00,
|
|
9
|
+
Secp256k1: 0x01,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function normalizeSuiAddress(value: string, forceAdd0x = false): string {
|
|
13
|
+
let address = value.toLowerCase();
|
|
14
|
+
if (!forceAdd0x && address.startsWith('0x')) {
|
|
15
|
+
address = address.slice(2);
|
|
16
|
+
}
|
|
17
|
+
return `0x${address.padStart(SUI_ADDRESS_LENGTH * 2, '0')}`.toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function publicKeyToAddress(publicKey: string) {
|
|
21
|
+
const tmp = new Uint8Array(PUBLIC_KEY_SIZE + 1);
|
|
22
|
+
tmp.set([SIGNATURE_SCHEME_TO_FLAG.ED25519]);
|
|
23
|
+
tmp.set(hexToBytes(publicKey), 1);
|
|
24
|
+
|
|
25
|
+
return normalizeSuiAddress(
|
|
26
|
+
bytesToHex(blake2b(tmp, { dkLen: 32 })).slice(0, SUI_ADDRESS_LENGTH * 2)
|
|
27
|
+
);
|
|
28
|
+
}
|