@injectivelabs/wallet-ledger 1.16.39-alpha.1 → 1.17.2-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.
@@ -99,7 +99,7 @@ var AccountManager$1 = class {
99
99
  const result = await this.ledger.getAddress(path);
100
100
  const hdKey = {
101
101
  publicKey: (0, __injectivelabs_sdk_ts_utils.hexToUint8Array)(result.publicKey),
102
- chainCode: (0, __injectivelabs_sdk_ts_utils.hexToUint8Array)(result.chainCode || "")
102
+ chainCode: result.chainCode ? (0, __injectivelabs_sdk_ts_utils.hexToUint8Array)(result.chainCode) : new Uint8Array(32)
103
103
  };
104
104
  const address = result.address || addressOfHDKey(hdKey);
105
105
  this.wallets.push({
@@ -364,6 +364,9 @@ var LedgerBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
364
364
  this.ledger = new LedgerTransport$1();
365
365
  this.evmOptions = args.evmOptions;
366
366
  }
367
+ setMetadata(metadata) {
368
+ this.metadata = metadata;
369
+ }
367
370
  async getWalletDeviceType() {
368
371
  return Promise.resolve(__injectivelabs_wallet_base.WalletDeviceType.Hardware);
369
372
  }
@@ -373,6 +376,10 @@ var LedgerBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
373
376
  async disconnect() {
374
377
  this.ledger = await this.ledger.refresh();
375
378
  }
379
+ async getDerivationPath(address) {
380
+ var _this$metadata;
381
+ return ((_this$metadata = this.metadata) === null || _this$metadata === void 0 ? void 0 : _this$metadata.derivationPath) ? this.metadata.derivationPath : (await this.getWalletForAddress(address)).derivationPath;
382
+ }
376
383
  async getAddresses() {
377
384
  const { baseDerivationPath, derivationPathType } = this;
378
385
  try {
@@ -428,7 +435,7 @@ var LedgerBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
428
435
  return response;
429
436
  }
430
437
  async signEip712TypedData(eip712json, address) {
431
- const { derivationPath } = await this.getWalletForAddress(address);
438
+ const derivationPath = await this.getDerivationPath(address);
432
439
  const object = JSON.parse(eip712json);
433
440
  try {
434
441
  const result = await (await this.ledger.getInstance()).signEIP712Message(derivationPath, object);
@@ -472,7 +479,7 @@ var LedgerBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
472
479
  }
473
480
  async signArbitrary(signer, data) {
474
481
  try {
475
- const { derivationPath } = await this.getWalletForAddress(signer);
482
+ const derivationPath = await this.getDerivationPath(signer);
476
483
  const result = await (await this.ledger.getInstance()).signPersonalMessage(derivationPath, (0, __injectivelabs_sdk_ts_utils.uint8ArrayToHex)((0, __injectivelabs_sdk_ts_utils.stringToUint8Array)((0, __injectivelabs_sdk_ts_utils.toUtf8)(data))));
477
484
  const v = result.v.toString(16).padStart(2, "0");
478
485
  const combined = `${result.r}${result.s}${v}`;
@@ -530,7 +537,7 @@ var LedgerBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
530
537
  const serializedTxHex = (0, viem.serializeTransaction)(eip1559TxData).slice(2);
531
538
  try {
532
539
  const ledger = await this.ledger.getInstance();
533
- const { derivationPath } = await this.getWalletForAddress(args.address);
540
+ const derivationPath = await this.getDerivationPath(args.address);
534
541
  const txSig = await ledger.clearSignTransaction(derivationPath, serializedTxHex, {
535
542
  erc20: true,
536
543
  externalPlugins: true,
@@ -551,8 +558,8 @@ var LedgerBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
551
558
  }
552
559
  }
553
560
  async getWalletForAddress(address) {
554
- var _this$metadata;
555
- if ((_this$metadata = this.metadata) === null || _this$metadata === void 0 ? void 0 : _this$metadata.derivationPath) return {
561
+ var _this$metadata2;
562
+ if ((_this$metadata2 = this.metadata) === null || _this$metadata2 === void 0 ? void 0 : _this$metadata2.derivationPath) return {
556
563
  address,
557
564
  baseDerivationPath: this.metadata.baseDerivationPath || this.baseDerivationPath,
558
565
  derivationPath: this.metadata.derivationPath
@@ -574,10 +581,10 @@ var LedgerBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
574
581
  }
575
582
  }
576
583
  async getEip1193Provider() {
577
- var _this$metadata2;
584
+ var _this$metadata3;
578
585
  return new LedgerEip1193Provider(this.ledger, {
579
586
  chainId: this.evmOptions.evmChainId.toString(),
580
- derivationPath: (_this$metadata2 = this.metadata) === null || _this$metadata2 === void 0 ? void 0 : _this$metadata2.derivationPath
587
+ derivationPath: (_this$metadata3 = this.metadata) === null || _this$metadata3 === void 0 ? void 0 : _this$metadata3.derivationPath
581
588
  });
582
589
  }
583
590
  async getPublicClient(evmChainId) {
@@ -1,4 +1,4 @@
1
- import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, Eip1193Provider, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
1
+ import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, Eip1193Provider, SendTransactionOptions, StdSignDoc, WalletDeviceType, WalletMetadata } from "@injectivelabs/wallet-base";
2
2
  import { AccountAddress, ChainId, EvmChainId } from "@injectivelabs/ts-types";
3
3
  import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
4
4
  import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
@@ -37,9 +37,11 @@ declare class LedgerBase extends BaseConcreteStrategy implements ConcreteWalletS
37
37
  constructor(args: ConcreteEvmWalletStrategyArgs & {
38
38
  derivationPathType: LedgerDerivationPathType;
39
39
  });
40
+ setMetadata(metadata: WalletMetadata): void;
40
41
  getWalletDeviceType(): Promise<WalletDeviceType>;
41
42
  enable(): Promise<boolean>;
42
43
  disconnect(): Promise<void>;
44
+ protected getDerivationPath(address: string): Promise<string>;
43
45
  getAddresses(): Promise<string[]>;
44
46
  getAddressesInfo(): Promise<{
45
47
  address: string;
@@ -1,5 +1,5 @@
1
1
  import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
2
- import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, Eip1193Provider, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
2
+ import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, Eip1193Provider, SendTransactionOptions, StdSignDoc, WalletDeviceType, WalletMetadata } from "@injectivelabs/wallet-base";
3
3
  import { AccountAddress, ChainId, EvmChainId } from "@injectivelabs/ts-types";
4
4
  import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
5
5
 
@@ -37,9 +37,11 @@ declare class LedgerBase extends BaseConcreteStrategy implements ConcreteWalletS
37
37
  constructor(args: ConcreteEvmWalletStrategyArgs & {
38
38
  derivationPathType: LedgerDerivationPathType;
39
39
  });
40
+ setMetadata(metadata: WalletMetadata): void;
40
41
  getWalletDeviceType(): Promise<WalletDeviceType>;
41
42
  enable(): Promise<boolean>;
42
43
  disconnect(): Promise<void>;
44
+ protected getDerivationPath(address: string): Promise<string>;
43
45
  getAddresses(): Promise<string[]>;
44
46
  getAddressesInfo(): Promise<{
45
47
  address: string;
package/dist/esm/index.js CHANGED
@@ -99,7 +99,7 @@ var AccountManager$1 = class {
99
99
  const result = await this.ledger.getAddress(path);
100
100
  const hdKey = {
101
101
  publicKey: hexToUint8Array(result.publicKey),
102
- chainCode: hexToUint8Array(result.chainCode || "")
102
+ chainCode: result.chainCode ? hexToUint8Array(result.chainCode) : new Uint8Array(32)
103
103
  };
104
104
  const address = result.address || addressOfHDKey(hdKey);
105
105
  this.wallets.push({
@@ -364,6 +364,9 @@ var LedgerBase = class extends BaseConcreteStrategy {
364
364
  this.ledger = new LedgerTransport$1();
365
365
  this.evmOptions = args.evmOptions;
366
366
  }
367
+ setMetadata(metadata) {
368
+ this.metadata = metadata;
369
+ }
367
370
  async getWalletDeviceType() {
368
371
  return Promise.resolve(WalletDeviceType.Hardware);
369
372
  }
@@ -373,6 +376,10 @@ var LedgerBase = class extends BaseConcreteStrategy {
373
376
  async disconnect() {
374
377
  this.ledger = await this.ledger.refresh();
375
378
  }
379
+ async getDerivationPath(address) {
380
+ var _this$metadata;
381
+ return ((_this$metadata = this.metadata) === null || _this$metadata === void 0 ? void 0 : _this$metadata.derivationPath) ? this.metadata.derivationPath : (await this.getWalletForAddress(address)).derivationPath;
382
+ }
376
383
  async getAddresses() {
377
384
  const { baseDerivationPath, derivationPathType } = this;
378
385
  try {
@@ -428,7 +435,7 @@ var LedgerBase = class extends BaseConcreteStrategy {
428
435
  return response;
429
436
  }
430
437
  async signEip712TypedData(eip712json, address) {
431
- const { derivationPath } = await this.getWalletForAddress(address);
438
+ const derivationPath = await this.getDerivationPath(address);
432
439
  const object = JSON.parse(eip712json);
433
440
  try {
434
441
  const result = await (await this.ledger.getInstance()).signEIP712Message(derivationPath, object);
@@ -472,7 +479,7 @@ var LedgerBase = class extends BaseConcreteStrategy {
472
479
  }
473
480
  async signArbitrary(signer, data) {
474
481
  try {
475
- const { derivationPath } = await this.getWalletForAddress(signer);
482
+ const derivationPath = await this.getDerivationPath(signer);
476
483
  const result = await (await this.ledger.getInstance()).signPersonalMessage(derivationPath, uint8ArrayToHex(stringToUint8Array(toUtf8(data))));
477
484
  const v = result.v.toString(16).padStart(2, "0");
478
485
  const combined = `${result.r}${result.s}${v}`;
@@ -530,7 +537,7 @@ var LedgerBase = class extends BaseConcreteStrategy {
530
537
  const serializedTxHex = serializeTransaction(eip1559TxData).slice(2);
531
538
  try {
532
539
  const ledger = await this.ledger.getInstance();
533
- const { derivationPath } = await this.getWalletForAddress(args.address);
540
+ const derivationPath = await this.getDerivationPath(args.address);
534
541
  const txSig = await ledger.clearSignTransaction(derivationPath, serializedTxHex, {
535
542
  erc20: true,
536
543
  externalPlugins: true,
@@ -551,8 +558,8 @@ var LedgerBase = class extends BaseConcreteStrategy {
551
558
  }
552
559
  }
553
560
  async getWalletForAddress(address) {
554
- var _this$metadata;
555
- if ((_this$metadata = this.metadata) === null || _this$metadata === void 0 ? void 0 : _this$metadata.derivationPath) return {
561
+ var _this$metadata2;
562
+ if ((_this$metadata2 = this.metadata) === null || _this$metadata2 === void 0 ? void 0 : _this$metadata2.derivationPath) return {
556
563
  address,
557
564
  baseDerivationPath: this.metadata.baseDerivationPath || this.baseDerivationPath,
558
565
  derivationPath: this.metadata.derivationPath
@@ -574,10 +581,10 @@ var LedgerBase = class extends BaseConcreteStrategy {
574
581
  }
575
582
  }
576
583
  async getEip1193Provider() {
577
- var _this$metadata2;
584
+ var _this$metadata3;
578
585
  return new LedgerEip1193Provider(this.ledger, {
579
586
  chainId: this.evmOptions.evmChainId.toString(),
580
- derivationPath: (_this$metadata2 = this.metadata) === null || _this$metadata2 === void 0 ? void 0 : _this$metadata2.derivationPath
587
+ derivationPath: (_this$metadata3 = this.metadata) === null || _this$metadata3 === void 0 ? void 0 : _this$metadata3.derivationPath
581
588
  });
582
589
  }
583
590
  async getPublicClient(evmChainId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-ledger",
3
- "version": "1.16.39-alpha.1",
3
+ "version": "1.17.2-alpha.0",
4
4
  "description": "Ledger wallet strategy for use with @injectivelabs/wallet-core.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -44,10 +44,10 @@
44
44
  "@ledgerhq/hw-transport-webhid": "^6.30.9",
45
45
  "@ledgerhq/hw-transport-webusb": "^6.29.13",
46
46
  "viem": "^2.41.2",
47
- "@injectivelabs/exceptions": "1.16.39-alpha.0",
48
- "@injectivelabs/sdk-ts": "1.16.39-alpha.1",
49
- "@injectivelabs/ts-types": "1.16.39-alpha.0",
50
- "@injectivelabs/wallet-base": "1.16.39-alpha.1"
47
+ "@injectivelabs/exceptions": "1.17.2-alpha.0",
48
+ "@injectivelabs/ts-types": "1.17.2-alpha.0",
49
+ "@injectivelabs/sdk-ts": "1.17.2-alpha.0",
50
+ "@injectivelabs/wallet-base": "1.17.2-alpha.0"
51
51
  },
52
52
  "publishConfig": {
53
53
  "access": "public"