@sidhujag/sysweb3-keyring 1.0.628 → 2.1.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.
Files changed (131) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +174 -0
  3. package/cjs/bip84-native.js +8 -0
  4. package/cjs/bip84-native.js.map +1 -0
  5. package/cjs/hardware-wallet-manager.js +302 -128
  6. package/cjs/hardware-wallet-manager.js.map +1 -1
  7. package/cjs/keyring-core.js +319 -0
  8. package/cjs/keyring-core.js.map +1 -1
  9. package/cjs/keyring-manager.js +9 -3
  10. package/cjs/keyring-manager.js.map +1 -1
  11. package/cjs/ledger/bitcoin_client/lib/appClient.js.map +1 -1
  12. package/cjs/ledger/host-types.js +10 -0
  13. package/cjs/ledger/host-types.js.map +1 -0
  14. package/cjs/ledger/index.js +243 -447
  15. package/cjs/ledger/index.js.map +1 -1
  16. package/cjs/ledger/prepare-psbt.js +177 -0
  17. package/cjs/ledger/prepare-psbt.js.map +1 -0
  18. package/cjs/public-bip84.js +157 -0
  19. package/cjs/public-bip84.js.map +1 -0
  20. package/cjs/software-hd-account.js +23 -0
  21. package/cjs/software-hd-account.js.map +1 -0
  22. package/cjs/software-utxo-account.js +12 -0
  23. package/cjs/software-utxo-account.js.map +1 -0
  24. package/cjs/software.js +24 -0
  25. package/cjs/software.js.map +1 -1
  26. package/cjs/transactions/bip84-native-plan.js +481 -0
  27. package/cjs/transactions/bip84-native-plan.js.map +1 -0
  28. package/cjs/transactions/ethereum.js +55 -10
  29. package/cjs/transactions/ethereum.js.map +1 -1
  30. package/cjs/transactions/hardware-psbt.js +36 -44
  31. package/cjs/transactions/hardware-psbt.js.map +1 -1
  32. package/cjs/transactions/prepared-bip84.js +214 -0
  33. package/cjs/transactions/prepared-bip84.js.map +1 -0
  34. package/cjs/transactions/prepared-evm.js +197 -0
  35. package/cjs/transactions/prepared-evm.js.map +1 -0
  36. package/cjs/trezor/connect.js +243 -0
  37. package/cjs/trezor/connect.js.map +1 -0
  38. package/cjs/trezor/index.js +96 -58
  39. package/cjs/trezor/index.js.map +1 -1
  40. package/cjs/trezor/witness.js +25 -0
  41. package/cjs/trezor/witness.js.map +1 -0
  42. package/cjs/utils/psbt-account-scope.js +5 -3
  43. package/cjs/utils/psbt-account-scope.js.map +1 -1
  44. package/esm/errorUtils.js +72 -0
  45. package/esm/errorUtils.js.map +1 -0
  46. package/esm/ethers-v6.js +207 -0
  47. package/esm/ethers-v6.js.map +1 -0
  48. package/esm/hardware-wallet-manager.js +643 -0
  49. package/esm/hardware-wallet-manager.js.map +1 -0
  50. package/esm/ledger/bitcoin_client/lib/appClient.js +279 -0
  51. package/esm/ledger/bitcoin_client/lib/appClient.js.map +1 -0
  52. package/esm/ledger/bitcoin_client/lib/bip32.js +49 -0
  53. package/esm/ledger/bitcoin_client/lib/bip32.js.map +1 -0
  54. package/esm/ledger/bitcoin_client/lib/buffertools.js +119 -0
  55. package/esm/ledger/bitcoin_client/lib/buffertools.js.map +1 -0
  56. package/esm/ledger/bitcoin_client/lib/clientCommands.js +269 -0
  57. package/esm/ledger/bitcoin_client/lib/clientCommands.js.map +1 -0
  58. package/esm/ledger/bitcoin_client/lib/merkelizedPsbt.js +50 -0
  59. package/esm/ledger/bitcoin_client/lib/merkelizedPsbt.js.map +1 -0
  60. package/esm/ledger/bitcoin_client/lib/merkle.js +111 -0
  61. package/esm/ledger/bitcoin_client/lib/merkle.js.map +1 -0
  62. package/esm/ledger/bitcoin_client/lib/merkleMap.js +42 -0
  63. package/esm/ledger/bitcoin_client/lib/merkleMap.js.map +1 -0
  64. package/esm/ledger/bitcoin_client/lib/policy.js +68 -0
  65. package/esm/ledger/bitcoin_client/lib/policy.js.map +1 -0
  66. package/esm/ledger/bitcoin_client/lib/psbtv2.js +645 -0
  67. package/esm/ledger/bitcoin_client/lib/psbtv2.js.map +1 -0
  68. package/esm/ledger/bitcoin_client/lib/varint.js +108 -0
  69. package/esm/ledger/bitcoin_client/lib/varint.js.map +1 -0
  70. package/esm/ledger/consts.js +4 -0
  71. package/esm/ledger/consts.js.map +1 -0
  72. package/esm/ledger/dmk-evm.js +258 -0
  73. package/esm/ledger/dmk-evm.js.map +1 -0
  74. package/esm/ledger/dmk-session.js +264 -0
  75. package/esm/ledger/dmk-session.js.map +1 -0
  76. package/esm/ledger/dmk-utxo.js +279 -0
  77. package/esm/ledger/dmk-utxo.js.map +1 -0
  78. package/esm/ledger/host-types.js +5 -0
  79. package/esm/ledger/host-types.js.map +1 -0
  80. package/esm/ledger/index.js +268 -0
  81. package/esm/ledger/index.js.map +1 -0
  82. package/esm/ledger/prepare-psbt.js +141 -0
  83. package/esm/ledger/prepare-psbt.js.map +1 -0
  84. package/esm/ledger/types.js +2 -0
  85. package/esm/ledger/types.js.map +1 -0
  86. package/esm/ledger-host.js +36 -0
  87. package/esm/ledger-host.js.map +1 -0
  88. package/esm/private-records.js +153 -0
  89. package/esm/private-records.js.map +1 -0
  90. package/esm/providers.js +588 -0
  91. package/esm/providers.js.map +1 -0
  92. package/esm/signers.js +28 -0
  93. package/esm/signers.js.map +1 -0
  94. package/esm/trezor/connect.js +206 -0
  95. package/esm/trezor/connect.js.map +1 -0
  96. package/esm/trezor/index.js +876 -0
  97. package/esm/trezor/index.js.map +1 -0
  98. package/esm/trezor/witness.js +21 -0
  99. package/esm/trezor/witness.js.map +1 -0
  100. package/esm/types.js +17 -0
  101. package/esm/types.js.map +1 -0
  102. package/esm/utils/derivation-paths.js +109 -0
  103. package/esm/utils/derivation-paths.js.map +1 -0
  104. package/esm/utils/psbt-account-scope.js +310 -0
  105. package/esm/utils/psbt-account-scope.js.map +1 -0
  106. package/package.json +34 -9
  107. package/types/bip84-native.d.ts +3 -0
  108. package/types/hardware-wallet-manager.d.ts +12 -19
  109. package/types/keyring-core.d.ts +14 -0
  110. package/types/keyring-manager.d.ts +2 -1
  111. package/types/ledger/bitcoin_client/lib/appClient.d.ts +6 -3
  112. package/types/ledger/dmk-evm.d.ts +8 -0
  113. package/types/ledger/dmk-session.d.ts +60 -0
  114. package/types/ledger/dmk-utxo.d.ts +26 -0
  115. package/types/ledger/host-types.d.ts +131 -0
  116. package/types/ledger/index.d.ts +21 -58
  117. package/types/ledger/prepare-psbt.d.ts +3 -0
  118. package/types/ledger/types.d.ts +3 -0
  119. package/types/ledger-host.d.ts +7 -0
  120. package/types/public-bip84.d.ts +39 -0
  121. package/types/software-hd-account.d.ts +16 -0
  122. package/types/software-utxo-account.d.ts +13 -0
  123. package/types/software.d.ts +26 -0
  124. package/types/transactions/bip84-native-plan.d.ts +83 -0
  125. package/types/transactions/ethereum.d.ts +1 -1
  126. package/types/transactions/prepared-bip84.d.ts +27 -0
  127. package/types/transactions/prepared-evm.d.ts +53 -0
  128. package/types/trezor/connect.d.ts +42 -0
  129. package/types/trezor/index.d.ts +22 -4
  130. package/types/trezor/witness.d.ts +3 -0
  131. package/types/utils/psbt-account-scope.d.ts +1 -0
@@ -1,5 +1,5 @@
1
- import Transport from '@ledgerhq/hw-transport';
2
1
  import { EventEmitter } from 'events';
2
+ import type { LedgerHost } from './ledger/host-types';
3
3
  export declare enum HardwareWalletType {
4
4
  LEDGER = "ledger",
5
5
  TREZOR = "trezor"
@@ -31,25 +31,22 @@ export interface HardwareWalletStatus {
31
31
  * Hardware Wallet Manager with connection pooling, status monitoring, and error recovery
32
32
  */
33
33
  export declare class HardwareWalletManager extends EventEmitter {
34
+ private readonly ledgerHost?;
34
35
  private connectionPool;
35
36
  private statusMonitorInterval;
36
- private readonly CONNECTION_TIMEOUT;
37
+ private unsubscribeTrezor?;
38
+ private lifecycleGeneration;
39
+ private trezorInitialization?;
40
+ private destruction?;
41
+ private ledgerInitialization?;
37
42
  private readonly IDLE_TIMEOUT;
38
43
  private readonly STATUS_CHECK_INTERVAL;
39
44
  private readonly retryConfig;
40
- constructor();
41
- /**
42
- * Get or create a Ledger connection with retry logic
43
- */
44
- getLedgerConnection(): Promise<Transport>;
45
- /**
46
- * Create Ledger connection with exponential backoff retry
47
- */
48
- private createLedgerConnectionWithRetry;
49
- /**
50
- * Create Ledger transport with timeout
51
- */
52
- private createLedgerTransport;
45
+ constructor(ledgerHost?: LedgerHost | undefined);
46
+ private observeTrezor;
47
+ /** Raw transports are deliberately unavailable through the semantic host boundary. */
48
+ getLedgerConnection(): Promise<never>;
49
+ private initializeLedger;
53
50
  /**
54
51
  * Initialize Trezor with retry logic
55
52
  */
@@ -94,10 +91,6 @@ export declare class HardwareWalletManager extends EventEmitter {
94
91
  * Calculate exponential backoff delay
95
92
  */
96
93
  private calculateBackoffDelay;
97
- /**
98
- * Create a timeout promise
99
- */
100
- private createTimeoutPromise;
101
94
  /**
102
95
  * Delay helper
103
96
  */
@@ -1,10 +1,15 @@
1
1
  import { INetwork, INetworkType } from '@sidhujag/sysweb3-network';
2
2
  import { IDecryptPrivateRecordParams, IEncryptedPrivateRecord, IEncryptPrivateRecordParams } from './private-records';
3
3
  import { SyscoinHDSigner } from './signers';
4
+ import { Bip84HdPublicRequest, Bip84HdPublicResult } from './software-utxo-account';
5
+ import { Bip84Guard } from './transactions/bip84-native-plan';
6
+ import { PreparedBip84SigningRequest, SignedBip84NativeTransaction } from './transactions/prepared-bip84';
4
7
  import { type ISyscoinHardwareSigners } from './transactions/syscoin-core';
5
8
  import { IKeyringAccountState, ICreateSmartAccountParams, ISyscoinTransactions, KeyringAccountType, IEthereumTransactions } from './types';
6
9
  import type { LedgerKeyring } from './ledger';
10
+ import type { EncryptedEvmHdRuntimeAccount, EvmHdRuntimeAccountOptions, EvmHdRuntimeAccountRequest } from './software-hd-account';
7
11
  import type { VaultPersistence, VaultStoragePort } from './storage-core';
12
+ import type { PreparedEvmSigningOptions, PreparedSoftwareEvmSigningRequest, SignedPreparedEvmTransaction } from './transactions/prepared-evm';
8
13
  import type { TrezorKeyring } from './trezor';
9
14
  /** Explicit asynchronous host storage; no browser or global DI fallback. */
10
15
  export interface KeyringStoragePort extends VaultStoragePort {
@@ -71,6 +76,7 @@ export declare class KeyringCore<TLedger extends KeyringLedgerSigner | undefined
71
76
  private sessionPassword;
72
77
  private sessionMnemonic;
73
78
  private privateRecordSessionRevision;
79
+ private bip84Operation;
74
80
  constructor(dependencies: KeyringCoreDependencies<TLedger, TTrezor>);
75
81
  private createSyscoinTransactions;
76
82
  private requireLedgerSigner;
@@ -185,6 +191,14 @@ export declare class KeyringCore<TLedger extends KeyringLedgerSigner | undefined
185
191
  */
186
192
  private getDecryptedPrivateKey;
187
193
  private capturePsbtSigningContext;
194
+ /** Fixed-profile public UTXO derivation; private material remains operation-local. */
195
+ protected deriveSoftwareBip84HdPublicAccount(input: Bip84HdPublicRequest, options: Bip84Guard): Promise<Bip84HdPublicResult>;
196
+ /** Fixed selected-account native signing. No storage, discovery or broadcast. */
197
+ protected signPreparedSoftwareBip84Transaction(input: PreparedBip84SigningRequest, options: Bip84Guard): Promise<SignedBip84NativeTransaction>;
198
+ /** Fixed-path derivation for an authenticated software host; no persistence. */
199
+ protected deriveSoftwareEvmHdRuntimeAccount(input: EvmHdRuntimeAccountRequest, options: EvmHdRuntimeAccountOptions): Promise<EncryptedEvmHdRuntimeAccount>;
200
+ /** The software facade owns this public capability; no device fallback. */
201
+ protected signPreparedSoftwareEvmTransaction(input: PreparedSoftwareEvmSigningRequest, options: PreparedEvmSigningOptions): SignedPreparedEvmTransaction;
188
202
  private getSigner;
189
203
  private getReadOnlySigner;
190
204
  private writeUtf8Diagnostic;
@@ -3,9 +3,10 @@ import { KeyringCore } from './keyring-core';
3
3
  import { LedgerKeyring } from './ledger';
4
4
  import { TrezorKeyring } from './trezor';
5
5
  import type { IKeyringManager } from './types';
6
+ import type { LedgerHost } from './ledger/host-types';
6
7
  export type { ISysAccount } from './keyring-core';
7
8
  /** Existing browser entry. Native/software hosts must use the software entry. */
8
9
  export declare class KeyringManager extends KeyringCore<LedgerKeyring, TrezorKeyring> implements IKeyringManager {
9
- constructor(sharedHardwareWalletManager?: HardwareWalletManager);
10
+ constructor(sharedHardwareWalletManager?: HardwareWalletManager, ledgerHost?: LedgerHost);
10
11
  static createInitialized(seed: string, password: string, vaultStateGetter: () => any): Promise<KeyringManager>;
11
12
  }
@@ -1,6 +1,9 @@
1
- import Transport from '@ledgerhq/hw-transport';
2
1
  import { WalletPolicy } from './policy';
3
2
  import { PsbtV2 } from './psbtv2';
3
+ /** The Bitcoin protocol needs APDU exchange only, not a vendor transport class. */
4
+ export interface BitcoinAppTransport {
5
+ send(cla: number, ins: number, p1: number, p2: number, data?: Buffer, acceptedStatusCodes?: number[]): Promise<Buffer>;
6
+ }
4
7
  /**
5
8
  * This class represents a partial signature produced by the app during signing.
6
9
  * It always contains the `signature` and the corresponding `pubkey` whose private key
@@ -18,8 +21,8 @@ export declare class PartialSignature {
18
21
  * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md
19
22
  */
20
23
  export declare class AppClient {
21
- readonly transport: Transport;
22
- constructor(transport: Transport);
24
+ readonly transport: BitcoinAppTransport;
25
+ constructor(transport: BitcoinAppTransport);
23
26
  private makeRequest;
24
27
  /**
25
28
  * Returns an object containing the currently running app's name, version and the device status flags.
@@ -0,0 +1,8 @@
1
+ import { type ContextModule } from '@ledgerhq/context-module';
2
+ import { type LedgerEvmHost, type LedgerEvmConfig } from './host-types';
3
+ import type { LedgerDmkSession } from './dmk-session';
4
+ export type { LedgerBlindSigningIntent, LedgerEvmConfig } from './host-types';
5
+ /** No remote metadata, transaction checks, or signing telemetry by default. */
6
+ export declare const offlineLedgerContext: ContextModule;
7
+ /** EVM facade preserves existing SDK signature formats and performs no broadcast. */
8
+ export declare function createLedgerEvmAdapter(session: LedgerDmkSession, config?: LedgerEvmConfig): LedgerEvmHost;
@@ -0,0 +1,60 @@
1
+ import { type LedgerOperationOptions } from './host-types';
2
+ import type { DeviceManagementKit } from '@ledgerhq/device-management-kit';
3
+ import type { Observable } from 'rxjs';
4
+ type Action<Output> = {
5
+ observable: Observable<{
6
+ status: 'not-started' | 'stopped';
7
+ } | {
8
+ status: 'pending';
9
+ intermediateValue: {
10
+ requiredUserInteraction: string;
11
+ step?: string;
12
+ };
13
+ } | {
14
+ status: 'completed';
15
+ output: Output;
16
+ } | {
17
+ status: 'error';
18
+ error: unknown;
19
+ }>;
20
+ cancel(): void;
21
+ };
22
+ export interface LedgerDmkOperation {
23
+ readonly dmk: DeviceManagementKit;
24
+ readonly sessionId: string;
25
+ readonly generation: number;
26
+ readonly signal: AbortSignal;
27
+ assertCurrent(): void;
28
+ runAction<Output>(createAction: () => Action<Output>): Promise<Output>;
29
+ }
30
+ /** One owner and one semantic operation at a time, across EVM and UTXO apps. */
31
+ export declare class LedgerDmkSession {
32
+ readonly dmk: DeviceManagementKit;
33
+ private generation;
34
+ private sessionId;
35
+ private queue;
36
+ private activeCancel;
37
+ private activeAbort;
38
+ private closing;
39
+ private stateSubscription;
40
+ private connectionAttempt;
41
+ private connectionAbort;
42
+ private readonly invalidationListeners;
43
+ constructor(dmk: DeviceManagementKit);
44
+ getStatus(): {
45
+ connected: boolean;
46
+ };
47
+ onInvalidated(listener: () => void): () => void;
48
+ private invalidate;
49
+ /** Device selection belongs to the visible host, never to a dapp request. */
50
+ connect(request?: {
51
+ useGrantedDevices?: boolean;
52
+ }, options?: LedgerOperationOptions): Promise<void>;
53
+ private connectDevice;
54
+ /** Cancel revokes the result and closes I/O; it cannot undo on-device approval. */
55
+ disconnect(): Promise<void>;
56
+ runExclusive<Output>(operation: (session: LedgerDmkOperation) => Promise<Output>, options?: LedgerOperationOptions): Promise<Output>;
57
+ runAction<Output>(createAction: (session: LedgerDmkOperation) => Action<Output>, options?: LedgerOperationOptions): Promise<Output>;
58
+ private awaitAction;
59
+ }
60
+ export {};
@@ -0,0 +1,26 @@
1
+ import { DeviceExchangeError, type ApduResponse, type Command, type InternalApi } from '@ledgerhq/device-management-kit';
2
+ import { type BitcoinAppTransport } from './bitcoin_client/lib/appClient';
3
+ import { LedgerDmkSession } from './dmk-session';
4
+ import { type LedgerUtxoAccount, type LedgerUtxoHost } from './host-types';
5
+ export declare class LedgerProtocolError extends DeviceExchangeError<number> {
6
+ readonly statusCode: number;
7
+ readonly code: string;
8
+ constructor(statusCode: number);
9
+ }
10
+ /** Preserves the existing Bitcoin/Syscoin APDU contract, including 0xe000. */
11
+ export declare class LedgerBitcoinCommand implements Command<Buffer, void, number> {
12
+ private readonly cla;
13
+ private readonly ins;
14
+ private readonly p1;
15
+ private readonly p2;
16
+ private readonly data;
17
+ private readonly acceptedStatusCodes;
18
+ readonly name = "PaliBitcoinProtocol";
19
+ constructor(cla: number, ins: number, p1: number, p2: number, data?: Uint8Array, acceptedStatusCodes?: number[]);
20
+ getApdu(): import("@ledgerhq/device-management-kit").Apdu;
21
+ parseResponse(response: ApduResponse): import("@ledgerhq/device-management-kit").CommandResult<Buffer<ArrayBufferLike>, number>;
22
+ }
23
+ /** Must be used inside a single DeviceAction; public dmk.sendCommand would requeue. */
24
+ export declare function createBitcoinAppTransport(internalApi: InternalApi, assertCurrent: () => void): BitcoinAppTransport;
25
+ export declare function ledgerUtxoApp(request: LedgerUtxoAccount): string;
26
+ export declare function createLedgerUtxoAdapter(session: LedgerDmkSession): LedgerUtxoHost;
@@ -0,0 +1,131 @@
1
+ /** Serializable Ledger requests. This module must remain free of device SDK imports. */
2
+ export interface LedgerProgress {
3
+ status: 'not-started' | 'pending' | 'stopped' | 'completed' | 'error';
4
+ requiredUserInteraction?: string;
5
+ step?: string;
6
+ }
7
+ export interface LedgerOperationOptions {
8
+ signal?: AbortSignal;
9
+ onProgress?: (progress: LedgerProgress) => void;
10
+ }
11
+ export interface LedgerUtxoAccount {
12
+ currency: string;
13
+ slip44: number;
14
+ accountIndex: number;
15
+ }
16
+ export interface LedgerPartialSignature {
17
+ inputIndex: number;
18
+ pubkeyHex: string;
19
+ signatureHex: string;
20
+ tapleafHashHex?: string;
21
+ }
22
+ export interface LedgerTypedData {
23
+ domain: Record<string, unknown>;
24
+ types: Record<string, {
25
+ name: string;
26
+ type: string;
27
+ }[]>;
28
+ primaryType: string;
29
+ message: Record<string, unknown>;
30
+ }
31
+ export type LedgerBlindSigningIntent = Readonly<{
32
+ kind: 'transaction';
33
+ accountIndex: number;
34
+ derivationPath: string;
35
+ expectedAddress: string;
36
+ unsignedTxHex: string;
37
+ chainId: string;
38
+ digest: string;
39
+ } | {
40
+ kind: 'typed-data';
41
+ accountIndex: number;
42
+ derivationPath: string;
43
+ expectedAddress: string;
44
+ version: 'V3' | 'V4';
45
+ data: LedgerTypedData;
46
+ digest: string;
47
+ }>;
48
+ /** Trusted host policy, never a field accepted from a dapp request. */
49
+ export interface LedgerEvmConfig {
50
+ /**
51
+ * The public DSK may fall back to blind signing. The host must disclose that
52
+ * limitation and approve this exact intent each time. No callback means deny.
53
+ */
54
+ confirmBlindSigning?: (intent: LedgerBlindSigningIntent, signal: AbortSignal) => boolean | Promise<boolean>;
55
+ }
56
+ export interface LedgerEvmHost {
57
+ getAddress(request: {
58
+ accountIndex: number;
59
+ checkOnDevice?: boolean;
60
+ chainId?: number;
61
+ }, options?: LedgerOperationOptions): Promise<{
62
+ address: string;
63
+ publicKey: string;
64
+ }>;
65
+ signTransaction(request: {
66
+ accountIndex: number;
67
+ unsignedTxHex: string;
68
+ expectedAddress: string;
69
+ }, options?: LedgerOperationOptions): Promise<{
70
+ r: string;
71
+ s: string;
72
+ v: string;
73
+ }>;
74
+ signPersonalMessage(request: {
75
+ accountIndex: number;
76
+ messageHex: string;
77
+ expectedAddress: string;
78
+ }, options?: LedgerOperationOptions): Promise<string>;
79
+ signTypedData(request: {
80
+ accountIndex: number;
81
+ version: 'V3' | 'V4';
82
+ data: LedgerTypedData;
83
+ expectedAddress: string;
84
+ }, options?: LedgerOperationOptions): Promise<string>;
85
+ }
86
+ export interface LedgerUtxoHost {
87
+ getXpub(request: LedgerUtxoAccount & {
88
+ checkOnDevice?: boolean;
89
+ }, options?: LedgerOperationOptions): Promise<string>;
90
+ getAddress(request: LedgerUtxoAccount & {
91
+ checkOnDevice?: boolean;
92
+ }, options?: LedgerOperationOptions): Promise<string>;
93
+ getAccount(request: LedgerUtxoAccount & {
94
+ checkOnDevice?: boolean;
95
+ }, options?: LedgerOperationOptions): Promise<{
96
+ xpub: string;
97
+ fingerprint: string;
98
+ address: string;
99
+ }>;
100
+ signMessage(request: LedgerUtxoAccount & {
101
+ message: string;
102
+ addressIndex?: number;
103
+ change?: boolean;
104
+ accountXpub: string;
105
+ }, options?: LedgerOperationOptions): Promise<string>;
106
+ signPsbt(request: LedgerUtxoAccount & {
107
+ psbtBase64: string;
108
+ accountXpub: string;
109
+ }, options?: LedgerOperationOptions): Promise<{
110
+ fingerprint: string;
111
+ signatures: LedgerPartialSignature[];
112
+ }>;
113
+ }
114
+ /** The wallet authority injects this port; an absent host never opens a device. */
115
+ export interface LedgerHost {
116
+ connect(request?: {
117
+ useGrantedDevices?: boolean;
118
+ }, options?: LedgerOperationOptions): Promise<void>;
119
+ disconnect(): Promise<void>;
120
+ getStatus(): {
121
+ connected: boolean;
122
+ };
123
+ readonly evm: LedgerEvmHost;
124
+ readonly utxo: LedgerUtxoHost;
125
+ }
126
+ export declare function ledgerHostError(code: string, message: string): Error & {
127
+ code: string;
128
+ };
129
+ export declare const ledgerCancelledError: () => Error & {
130
+ code: string;
131
+ };
@@ -1,62 +1,25 @@
1
- import Transport from '@ledgerhq/hw-transport';
2
- import SysUtxoClient from './bitcoin_client';
3
- import type { Psbt } from 'bitcoinjs-lib';
4
- import { IEvmMethods, IUTXOMethods } from './types';
5
- import LedgerEthClient from '@ledgerhq/hw-app-eth';
6
- import { HardwareWalletManager } from '../hardware-wallet-manager';
1
+ import { ConnectionStatus, HardwareWalletType } from '../hardware-wallet-manager';
2
+ import type { HardwareWalletManager } from '../hardware-wallet-manager';
3
+ import type { LedgerHost, LedgerUtxoHost } from './host-types';
4
+ import type { IEvmMethods, IUTXOMethods } from './types';
5
+ /** Small authority-side facade. Device SDKs belong exclusively in ledger-host. */
7
6
  export declare class LedgerKeyring {
8
- ledgerEVMClient: LedgerEthClient;
9
- ledgerUtxoClient: SysUtxoClient;
10
- private hdPath;
11
- evm: IEvmMethods;
12
- utxo: IUTXOMethods;
13
- transport: Transport | null;
14
- private hardwareWalletManager;
15
- private walletHmacCache;
16
- /**
17
- * @param sharedHardwareWalletManager Optional shared HardwareWalletManager instance.
18
- * If provided, this will be used instead of creating
19
- * a new instance. This allows multiple KeyringManagers
20
- * to share the same Ledger connection.
21
- */
22
- constructor(sharedHardwareWalletManager?: HardwareWalletManager);
23
- /**
24
- * Ensure Ledger is connected with automatic retry
25
- * Note: This is automatically called by all operations through executeWithRetry
26
- * External callers don't need to call this directly
27
- */
28
- ensureConnection(): Promise<void>;
29
- private getUtxoAddress;
7
+ private readonly sharedHardwareWalletManager?;
8
+ private readonly host?;
9
+ readonly evm: IEvmMethods;
10
+ readonly utxo: IUTXOMethods;
11
+ private generation;
12
+ constructor(sharedHardwareWalletManager?: HardwareWalletManager | undefined, host?: LedgerHost | undefined);
13
+ private requireHost;
14
+ private run;
15
+ ensureConnection: () => Promise<void>;
30
16
  verifyUtxoAddress: (accountIndex: number, currency: string, slip44: number) => Promise<string>;
31
- private getXpub;
32
- /**
33
- * Sign a UTXO message - public method used by transaction classes
34
- */
35
- signUtxoMessage: (path: string, message: string) => Promise<string>;
36
- private signEVMTransaction;
37
- private signPersonalMessage;
38
- private sanitizeData;
39
- private transformTypedData;
40
- private getEvmAddressAndPubKey;
41
- private signTypedData;
42
- private getMasterFingerprint;
43
- private buildWalletCacheKey;
44
- private getOrRegisterHmac;
45
- private setHdPath;
46
- /**
47
- * Convert PSBT to Ledger format with retry logic
48
- */
49
- convertToLedgerFormat(psbt: Psbt, accountXpub: string, accountId: number, currency: string, slip44: number): Promise<Psbt>;
50
- /**
51
- * Execute operation with automatic retry
52
- */
53
- private executeWithRetry;
54
- /**
55
- * Get hardware wallet status
56
- */
57
- getStatus(): import("../hardware-wallet-manager").HardwareWalletStatus | undefined;
58
- /**
59
- * Clean up resources
60
- */
17
+ signUtxoMessage: (request: Parameters<LedgerUtxoHost["signMessage"]>[0]) => Promise<string>;
18
+ signPsbt: (request: Parameters<LedgerUtxoHost["signPsbt"]>[0]) => ReturnType<LedgerUtxoHost["signPsbt"]>;
19
+ getStatus(): {
20
+ type: HardwareWalletType;
21
+ connected: boolean;
22
+ status: ConnectionStatus;
23
+ };
61
24
  destroy(): Promise<void>;
62
25
  }
@@ -0,0 +1,3 @@
1
+ import type { Psbt } from 'bitcoinjs-lib';
2
+ /** Enrich public PSBT metadata only. Callers must also enforce account scope. */
3
+ export declare function prepareLedgerPsbt(psbt: Psbt, accountXpub: string, accountId: number, currency: string, slip44: number, fingerprint: string): Psbt;
@@ -30,6 +30,7 @@ export interface IEvmMethods {
30
30
  signEVMTransaction: ({ rawTx, accountIndex, }: {
31
31
  accountIndex: number;
32
32
  rawTx: string;
33
+ expectedAddress: string;
33
34
  }) => Promise<{
34
35
  r: string;
35
36
  s: string;
@@ -38,10 +39,12 @@ export interface IEvmMethods {
38
39
  signPersonalMessage: ({ message, accountIndex, }: {
39
40
  accountIndex: number;
40
41
  message: string;
42
+ expectedAddress: string;
41
43
  }) => Promise<string>;
42
44
  signTypedData: ({ version, data, accountIndex, }: {
43
45
  accountIndex: number;
44
46
  data: any;
47
+ expectedAddress: string;
45
48
  version: SignTypedDataVersion;
46
49
  }) => Promise<string>;
47
50
  }
@@ -0,0 +1,7 @@
1
+ import type { LedgerHost, LedgerEvmConfig } from './ledger/host-types';
2
+ export interface LedgerDmkHostConfig extends LedgerEvmConfig {
3
+ /** Platform-owned DMK, allowing a future host to register its own transports. */
4
+ dmk?: object;
5
+ }
6
+ export declare function createLedgerDmkHost(config?: LedgerDmkHostConfig): LedgerHost;
7
+ export type { LedgerEvmConfig, LedgerBlindSigningIntent, LedgerHost, LedgerEvmHost, LedgerUtxoHost, LedgerUtxoAccount, LedgerPartialSignature, LedgerTypedData, LedgerOperationOptions, LedgerProgress, } from './ledger/host-types';
@@ -0,0 +1,39 @@
1
+ export type Bip84PublicNetwork = 'bitcoin' | 'syscoin';
2
+ export type Bip84PublicAccountRequest = Readonly<{
3
+ network: Bip84PublicNetwork;
4
+ accountKey: string;
5
+ }>;
6
+ export type Bip84PublicAccount = Readonly<{
7
+ network: Bip84PublicNetwork;
8
+ policy: 'bip84-p2wpkh';
9
+ canonicalKey: string;
10
+ accountIndex: number;
11
+ }>;
12
+ export type Bip84PublicAddressRequest = Bip84PublicAccountRequest & Readonly<{
13
+ branch: 0 | 1;
14
+ index: number;
15
+ }>;
16
+ export type Bip84PublicAddress = Readonly<{
17
+ account: Bip84PublicAccount;
18
+ branch: 0 | 1;
19
+ index: number;
20
+ address: string;
21
+ scriptPubKey: string;
22
+ }>;
23
+ export declare class PublicBip84Error extends Error {
24
+ readonly code: 'INVALID_INPUT' | 'INVALID_ACCOUNT' | 'INVALID_DERIVATION';
25
+ constructor(code: 'INVALID_INPUT' | 'INVALID_ACCOUNT' | 'INVALID_DERIVATION');
26
+ }
27
+ /**
28
+ * Validate one public account and normalize xpub/zpub aliases. The chosen
29
+ * network and BIP84 policy are explicit; ancestry/purpose is not attested.
30
+ * No keyring, storage, provider, randomness or wallet signing is involved.
31
+ * BIP32Factory runs its upstream deterministic ECC self-tests at module load.
32
+ */
33
+ export declare function parseBip84PublicAccount(request: Bip84PublicAccountRequest): Bip84PublicAccount;
34
+ /**
35
+ * Derive only /0/index or /1/index from a validated mainnet account key.
36
+ * One bounded input and two child derivations; no discovery, cache or range
37
+ * iteration. Callers own scan limits and privacy consent. Returned data is public.
38
+ */
39
+ export declare function deriveBip84PublicAddress(request: Bip84PublicAddressRequest): Bip84PublicAddress;
@@ -0,0 +1,16 @@
1
+ import type { IKeyringAccountState } from './types';
2
+ /** Fixed Ethereum BIP44 address index; not an arbitrary derivation path. */
3
+ export interface EvmHdRuntimeAccountRequest {
4
+ readonly index: number;
5
+ }
6
+ /** Trusted host guard must return undefined synchronously. */
7
+ export interface EvmHdRuntimeAccountOptions {
8
+ assertCurrent: () => void;
9
+ }
10
+ /**
11
+ * Internal runtime record, matching createFirstAccount/addNewAccount. Contains a
12
+ * password-encrypted xprv; never publish it or persist it as a public catalogue.
13
+ * No plaintext private key, mnemonic, or password is returned.
14
+ */
15
+ export type EncryptedEvmHdRuntimeAccount = IKeyringAccountState;
16
+ export declare function snapshotEvmHdIndex(value: EvmHdRuntimeAccountRequest): number;
@@ -0,0 +1,13 @@
1
+ import { Bip84PublicAccount, Bip84PublicAddress } from './public-bip84';
2
+ import { Bip84NetworkBinding } from './transactions/bip84-native-plan';
3
+ export type Bip84HdPublicRequest = Readonly<{
4
+ network: Bip84NetworkBinding;
5
+ accountIndex: number;
6
+ }>;
7
+ export type Bip84HdPublicResult = Readonly<{
8
+ type: 'HDAccount';
9
+ accountIndex: number;
10
+ account: Bip84PublicAccount;
11
+ receive: Bip84PublicAddress;
12
+ }>;
13
+ export declare function snapshotBip84HdPublicRequest(value: unknown): Bip84HdPublicRequest;
@@ -1,6 +1,11 @@
1
1
  /** Software-only entry: explicit host storage, no browser/device initialization. */
2
2
  import { KeyringCore } from './keyring-core';
3
3
  import type { KeyringStoragePort } from './keyring-core';
4
+ import type { EncryptedEvmHdRuntimeAccount, EvmHdRuntimeAccountOptions, EvmHdRuntimeAccountRequest } from './software-hd-account';
5
+ import type { Bip84HdPublicRequest, Bip84HdPublicResult } from './software-utxo-account';
6
+ import type { Bip84Guard } from './transactions/bip84-native-plan';
7
+ import type { PreparedBip84SigningRequest, SignedBip84NativeTransaction } from './transactions/prepared-bip84';
8
+ import type { PreparedEvmSigningOptions, PreparedSoftwareEvmSigningRequest, SignedPreparedEvmTransaction } from './transactions/prepared-evm';
4
9
  declare const softwareHostBrand: unique symbol;
5
10
  /** Opaque handle minted by createSoftwareKeyringHost; no injectable persistence. */
6
11
  export interface SoftwareKeyringHost {
@@ -10,6 +15,22 @@ export interface SoftwareKeyringHost {
10
15
  export declare const createSoftwareKeyringHost: (storage: KeyringStoragePort) => SoftwareKeyringHost;
11
16
  export declare class SoftwareKeyring extends KeyringCore<undefined, undefined> {
12
17
  constructor(host: SoftwareKeyringHost);
18
+ /**
19
+ * Derive a fixed-path Ethereum HD runtime account without network or storage
20
+ * writes. The returned password-encrypted xprv is internal runtime state,
21
+ * never a public account/catalogue DTO. The host owns index allocation.
22
+ */
23
+ deriveEvmHdRuntimeAccount(request: EvmHdRuntimeAccountRequest, options: EvmHdRuntimeAccountOptions): Promise<EncryptedEvmHdRuntimeAccount>;
24
+ /** Derive public BIP84 account data from the live seed; no storage or discovery. */
25
+ deriveBip84HdPublicAccount(request: Bip84HdPublicRequest, options: Bip84Guard): Promise<Bip84HdPublicResult>;
26
+ /** Sign the selected HD account's exact prepared native transaction offline. */
27
+ signPreparedBip84Transaction(request: PreparedBip84SigningRequest, options: Bip84Guard): Promise<SignedBip84NativeTransaction>;
28
+ /**
29
+ * Sign exactly the prepared envelope without RPC, fee/nonce discovery or
30
+ * broadcasting. The host must journal the result before submitting it.
31
+ * A later lock cannot revoke already returned signed bytes.
32
+ */
33
+ signPreparedEvmTransaction(request: PreparedSoftwareEvmSigningRequest, options: PreparedEvmSigningOptions): SignedPreparedEvmTransaction;
13
34
  /** Software authorities cannot rebind their backing store after creation. */
14
35
  setStorage: (client: any) => never;
15
36
  /** Sessions may move only through the core's same-authority transfer path. */
@@ -21,3 +42,8 @@ export { INetworkType } from '@sidhujag/sysweb3-network';
21
42
  export type { INetwork } from '@sidhujag/sysweb3-network';
22
43
  export type { KeyringStoragePort } from './keyring-core';
23
44
  export type { IKeyringAccountState } from './types';
45
+ export type { PreparedEvmTransaction, PreparedEvmSigningOptions, PreparedSoftwareEvmSigningRequest, SignedPreparedEvmTransaction, } from './transactions/prepared-evm';
46
+ export type { EncryptedEvmHdRuntimeAccount, EvmHdRuntimeAccountOptions, EvmHdRuntimeAccountRequest, } from './software-hd-account';
47
+ export type { Bip84HdPublicRequest, Bip84HdPublicResult, } from './software-utxo-account';
48
+ export type { Bip84Guard } from './transactions/bip84-native-plan';
49
+ export type { PreparedBip84SigningRequest, SignedBip84NativeTransaction, } from './transactions/prepared-bip84';