@sidhujag/sysweb3-keyring 1.0.627 → 2.0.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 (140) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +66 -0
  3. package/cjs/hardware-wallet-manager.js +302 -128
  4. package/cjs/hardware-wallet-manager.js.map +1 -1
  5. package/cjs/keyring-core.js +2605 -0
  6. package/cjs/keyring-core.js.map +1 -0
  7. package/cjs/keyring-manager.js +31 -2439
  8. package/cjs/keyring-manager.js.map +1 -1
  9. package/cjs/ledger/bitcoin_client/lib/appClient.js.map +1 -1
  10. package/cjs/ledger/host-types.js +10 -0
  11. package/cjs/ledger/host-types.js.map +1 -0
  12. package/cjs/ledger/index.js +243 -447
  13. package/cjs/ledger/index.js.map +1 -1
  14. package/cjs/ledger/prepare-psbt.js +177 -0
  15. package/cjs/ledger/prepare-psbt.js.map +1 -0
  16. package/cjs/software-hd-account.js +23 -0
  17. package/cjs/software-hd-account.js.map +1 -0
  18. package/cjs/software.js +74 -0
  19. package/cjs/software.js.map +1 -0
  20. package/cjs/storage-core.js +227 -0
  21. package/cjs/storage-core.js.map +1 -0
  22. package/cjs/storage.js +15 -210
  23. package/cjs/storage.js.map +1 -1
  24. package/cjs/transactions/ethereum.js +176 -39
  25. package/cjs/transactions/ethereum.js.map +1 -1
  26. package/cjs/transactions/evm-local-signer.js +11 -1
  27. package/cjs/transactions/evm-local-signer.js.map +1 -1
  28. package/cjs/transactions/hardware-psbt.js +159 -0
  29. package/cjs/transactions/hardware-psbt.js.map +1 -0
  30. package/cjs/transactions/prepared-evm.js +196 -0
  31. package/cjs/transactions/prepared-evm.js.map +1 -0
  32. package/cjs/transactions/syscoin-core.js +651 -0
  33. package/cjs/transactions/syscoin-core.js.map +1 -0
  34. package/cjs/transactions/syscoin.js +8 -768
  35. package/cjs/transactions/syscoin.js.map +1 -1
  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/types.js.map +1 -1
  43. package/cjs/utils/psbt-account-scope.js +5 -3
  44. package/cjs/utils/psbt-account-scope.js.map +1 -1
  45. package/esm/errorUtils.js +72 -0
  46. package/esm/errorUtils.js.map +1 -0
  47. package/esm/ethers-v6.js +207 -0
  48. package/esm/ethers-v6.js.map +1 -0
  49. package/esm/hardware-wallet-manager.js +643 -0
  50. package/esm/hardware-wallet-manager.js.map +1 -0
  51. package/esm/ledger/bitcoin_client/lib/appClient.js +279 -0
  52. package/esm/ledger/bitcoin_client/lib/appClient.js.map +1 -0
  53. package/esm/ledger/bitcoin_client/lib/bip32.js +49 -0
  54. package/esm/ledger/bitcoin_client/lib/bip32.js.map +1 -0
  55. package/esm/ledger/bitcoin_client/lib/buffertools.js +119 -0
  56. package/esm/ledger/bitcoin_client/lib/buffertools.js.map +1 -0
  57. package/esm/ledger/bitcoin_client/lib/clientCommands.js +269 -0
  58. package/esm/ledger/bitcoin_client/lib/clientCommands.js.map +1 -0
  59. package/esm/ledger/bitcoin_client/lib/merkelizedPsbt.js +50 -0
  60. package/esm/ledger/bitcoin_client/lib/merkelizedPsbt.js.map +1 -0
  61. package/esm/ledger/bitcoin_client/lib/merkle.js +111 -0
  62. package/esm/ledger/bitcoin_client/lib/merkle.js.map +1 -0
  63. package/esm/ledger/bitcoin_client/lib/merkleMap.js +42 -0
  64. package/esm/ledger/bitcoin_client/lib/merkleMap.js.map +1 -0
  65. package/esm/ledger/bitcoin_client/lib/policy.js +68 -0
  66. package/esm/ledger/bitcoin_client/lib/policy.js.map +1 -0
  67. package/esm/ledger/bitcoin_client/lib/psbtv2.js +645 -0
  68. package/esm/ledger/bitcoin_client/lib/psbtv2.js.map +1 -0
  69. package/esm/ledger/bitcoin_client/lib/varint.js +108 -0
  70. package/esm/ledger/bitcoin_client/lib/varint.js.map +1 -0
  71. package/esm/ledger/consts.js +4 -0
  72. package/esm/ledger/consts.js.map +1 -0
  73. package/esm/ledger/dmk-evm.js +258 -0
  74. package/esm/ledger/dmk-evm.js.map +1 -0
  75. package/esm/ledger/dmk-session.js +264 -0
  76. package/esm/ledger/dmk-session.js.map +1 -0
  77. package/esm/ledger/dmk-utxo.js +279 -0
  78. package/esm/ledger/dmk-utxo.js.map +1 -0
  79. package/esm/ledger/host-types.js +5 -0
  80. package/esm/ledger/host-types.js.map +1 -0
  81. package/esm/ledger/index.js +268 -0
  82. package/esm/ledger/index.js.map +1 -0
  83. package/esm/ledger/prepare-psbt.js +141 -0
  84. package/esm/ledger/prepare-psbt.js.map +1 -0
  85. package/esm/ledger/types.js +2 -0
  86. package/esm/ledger/types.js.map +1 -0
  87. package/esm/ledger-host.js +36 -0
  88. package/esm/ledger-host.js.map +1 -0
  89. package/esm/private-records.js +153 -0
  90. package/esm/private-records.js.map +1 -0
  91. package/esm/providers.js +588 -0
  92. package/esm/providers.js.map +1 -0
  93. package/esm/signers.js +28 -0
  94. package/esm/signers.js.map +1 -0
  95. package/esm/trezor/connect.js +206 -0
  96. package/esm/trezor/connect.js.map +1 -0
  97. package/esm/trezor/index.js +876 -0
  98. package/esm/trezor/index.js.map +1 -0
  99. package/esm/trezor/witness.js +21 -0
  100. package/esm/trezor/witness.js.map +1 -0
  101. package/esm/types.js +17 -0
  102. package/esm/types.js.map +1 -0
  103. package/esm/utils/derivation-paths.js +109 -0
  104. package/esm/utils/derivation-paths.js.map +1 -0
  105. package/esm/utils/psbt-account-scope.js +310 -0
  106. package/esm/utils/psbt-account-scope.js.map +1 -0
  107. package/package.json +55 -8
  108. package/types/hardware-wallet-manager.d.ts +12 -19
  109. package/types/keyring-core.d.ts +263 -0
  110. package/types/keyring-manager.d.ts +7 -224
  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/software-hd-account.d.ts +16 -0
  121. package/types/software.d.ts +39 -0
  122. package/types/storage-core.d.ts +22 -0
  123. package/types/storage.d.ts +1 -4
  124. package/types/transactions/ethereum.d.ts +17 -7
  125. package/types/transactions/evm-local-signer.d.ts +3 -1
  126. package/types/transactions/hardware-psbt.d.ts +7 -0
  127. package/types/transactions/prepared-evm.d.ts +53 -0
  128. package/types/transactions/syscoin-core.d.ts +92 -0
  129. package/types/transactions/syscoin.d.ts +8 -67
  130. package/types/trezor/connect.d.ts +42 -0
  131. package/types/trezor/index.d.ts +22 -4
  132. package/types/trezor/witness.d.ts +3 -0
  133. package/types/types.d.ts +10 -0
  134. package/types/utils/psbt-account-scope.d.ts +1 -0
  135. package/cjs/transactions/__tests__/integration.test.js +0 -237
  136. package/cjs/transactions/__tests__/integration.test.js.map +0 -1
  137. package/cjs/transactions/__tests__/syscoin.test.js +0 -361
  138. package/cjs/transactions/__tests__/syscoin.test.js.map +0 -1
  139. package/types/transactions/__tests__/integration.test.d.ts +0 -1
  140. package/types/transactions/__tests__/syscoin.test.d.ts +0 -1
@@ -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
  */
@@ -0,0 +1,263 @@
1
+ import { INetwork, INetworkType } from '@sidhujag/sysweb3-network';
2
+ import { IDecryptPrivateRecordParams, IEncryptedPrivateRecord, IEncryptPrivateRecordParams } from './private-records';
3
+ import { SyscoinHDSigner } from './signers';
4
+ import { type ISyscoinHardwareSigners } from './transactions/syscoin-core';
5
+ import { IKeyringAccountState, ICreateSmartAccountParams, ISyscoinTransactions, KeyringAccountType, IEthereumTransactions } from './types';
6
+ import type { LedgerKeyring } from './ledger';
7
+ import type { EncryptedEvmHdRuntimeAccount, EvmHdRuntimeAccountOptions, EvmHdRuntimeAccountRequest } from './software-hd-account';
8
+ import type { VaultPersistence, VaultStoragePort } from './storage-core';
9
+ import type { PreparedEvmSigningOptions, PreparedSoftwareEvmSigningRequest, SignedPreparedEvmTransaction } from './transactions/prepared-evm';
10
+ import type { TrezorKeyring } from './trezor';
11
+ /** Explicit asynchronous host storage; no browser or global DI fallback. */
12
+ export interface KeyringStoragePort extends VaultStoragePort {
13
+ get(key: string): Promise<any>;
14
+ deleteItem(key: string): Promise<void>;
15
+ /** Legacy adapter capability; fixed native hosts can omit it. */
16
+ setClient?(client: any): void;
17
+ }
18
+ /** Only the device capabilities consumed by the wallet authority. */
19
+ export interface KeyringLedgerSigner {
20
+ destroy: LedgerKeyring['destroy'];
21
+ evm: Pick<LedgerKeyring['evm'], 'getEvmAddressAndPubKey' | 'signTypedData' | 'signPersonalMessage' | 'signEVMTransaction'>;
22
+ utxo: Pick<LedgerKeyring['utxo'], 'getXpub'>;
23
+ verifyUtxoAddress: LedgerKeyring['verifyUtxoAddress'];
24
+ }
25
+ export type KeyringTrezorSigner = Pick<TrezorKeyring, 'destroy' | 'getAccountInfo' | 'getPublicKey' | 'signTypedData' | 'signMessage' | 'signEthTransaction' | 'verifyUtxoAddress'>;
26
+ export interface KeyringCoreDependencies<TLedger extends KeyringLedgerSigner | undefined, TTrezor extends KeyringTrezorSigner | undefined> {
27
+ /** Immutable identity shared only by keyrings in the same wallet authority. */
28
+ authority: object;
29
+ storage: KeyringStoragePort;
30
+ /** Must be bound to this authority's storage and shared across its keyrings. */
31
+ vaultPersistence: VaultPersistence;
32
+ ledgerSigner: TLedger;
33
+ trezorSigner: TTrezor;
34
+ /** Trusted host adapters; absent device capabilities fail closed. */
35
+ syscoinHardwareSigners?: ISyscoinHardwareSigners;
36
+ }
37
+ export interface ISysAccount {
38
+ address: string;
39
+ label?: string;
40
+ xprv?: string;
41
+ xpub: string;
42
+ }
43
+ /**
44
+ * Secure Buffer implementation for sensitive data
45
+ * Provides explicit memory clearing capability
46
+ */
47
+ declare class SecureBuffer {
48
+ private buffer;
49
+ private _isCleared;
50
+ constructor(data: string | Buffer);
51
+ get(): Buffer;
52
+ toString(): string;
53
+ clear(): void;
54
+ isCleared(): boolean;
55
+ }
56
+ export declare class KeyringCore<TLedger extends KeyringLedgerSigner | undefined = KeyringLedgerSigner | undefined, TTrezor extends KeyringTrezorSigner | undefined = KeyringTrezorSigner | undefined> {
57
+ trezorSigner: TTrezor;
58
+ ledgerSigner: TLedger;
59
+ initialTrezorAccountState: IKeyringAccountState;
60
+ initialLedgerAccountState: IKeyringAccountState;
61
+ utf8Error: boolean;
62
+ ethereumTransaction: IEthereumTransactions;
63
+ syscoinTransaction: ISyscoinTransactions;
64
+ private readonly authority;
65
+ private readonly storage;
66
+ private readonly vaultPersistence;
67
+ private readonly syscoinHardwareSigners;
68
+ private getVaultState;
69
+ setVaultStateGetter: (getter: () => any) => void;
70
+ private getVault;
71
+ private getActiveChain;
72
+ private accountAddressExists;
73
+ private sessionPassword;
74
+ private sessionMnemonic;
75
+ private privateRecordSessionRevision;
76
+ constructor(dependencies: KeyringCoreDependencies<TLedger, TTrezor>);
77
+ private createSyscoinTransactions;
78
+ private requireLedgerSigner;
79
+ private requireTrezorSigner;
80
+ initialize(seed: string, password: string, network?: INetwork): Promise<IKeyringAccountState>;
81
+ setStorage: (client: any) => void;
82
+ validateAccountType: (account: IKeyringAccountState) => KeyringAccountType.HDAccount | KeyringAccountType.Imported;
83
+ isUnlocked: () => boolean;
84
+ lockWallet: () => Promise<void>;
85
+ transferSessionTo: (targetKeyring: Pick<KeyringCore, "receiveSessionOwnership">) => void;
86
+ private acceptSessionFrom;
87
+ receiveSessionOwnership: (sessionPassword: SecureBuffer, sessionMnemonic: SecureBuffer) => void;
88
+ private replaceSessionBuffers;
89
+ addNewAccount: (label?: string) => Promise<IKeyringAccountState>;
90
+ createSmartAccount: ({ address, deriveAccount, label, metadata, }: ICreateSmartAccountParams) => Promise<IKeyringAccountState>;
91
+ /**
92
+ * Returns canLogin:false only when the first vault authentication fails.
93
+ * Storage, platform and session restoration failures reject so callers do
94
+ * not charge a failed password attempt for an operational error.
95
+ */
96
+ unlock(password: string): Promise<{
97
+ canLogin: boolean;
98
+ needsAccountCreation?: boolean;
99
+ }>;
100
+ getNewChangeAddress: () => Promise<string>;
101
+ getChangeAddress: (id: number) => Promise<string>;
102
+ getPubkey: (id: number, isChangeAddress: boolean) => Promise<string>;
103
+ getBip32Path: (id: number, isChangeAddress: boolean) => Promise<string>;
104
+ updateReceivingAddress: () => Promise<string>;
105
+ getAccountById: (id: number, accountType: KeyringAccountType) => Omit<IKeyringAccountState, "xprv">;
106
+ getPrivateKeyByAccountId: (id: number, accountType: KeyringAccountType, pwd: string) => Promise<string>;
107
+ getActiveAccount: () => {
108
+ activeAccount: Omit<IKeyringAccountState, "xprv">;
109
+ activeAccountType: KeyringAccountType;
110
+ };
111
+ private isDescriptor;
112
+ private isXpubLike;
113
+ private isWatchOnlyAccount;
114
+ getEncryptedXprv: (hd: SyscoinHDSigner) => string;
115
+ getSeed: (pwd: string) => Promise<any>;
116
+ deriveSLHDSASetupSecretForAccount: ({ accountIndex, }: {
117
+ accountIndex: number;
118
+ }) => Promise<{
119
+ derivationLabel: string;
120
+ setupSecretHex: string;
121
+ }>;
122
+ encryptSLHDSASessionState: (plainText: string) => string;
123
+ decryptSLHDSASessionState: (cipherText: string) => string;
124
+ private privateRecordSession;
125
+ /** Stable local profile identifier; never an account address or a key. */
126
+ getPrivateRecordProfileId(): Promise<string>;
127
+ /** Encrypt caller-owned bytes; persistence and encrypted backup belong to the caller. */
128
+ encryptPrivateRecord(params: IEncryptPrivateRecordParams): Promise<IEncryptedPrivateRecord>;
129
+ decryptPrivateRecord(params: IDecryptPrivateRecordParams): Promise<Uint8Array>;
130
+ setSignerNetwork: (network: INetwork) => Promise<{
131
+ activeChain?: INetworkType;
132
+ success: boolean;
133
+ }>;
134
+ forgetMainWallet: (pwd: string) => Promise<void>;
135
+ importWeb3Account: (mnemonicOrPrivKey: string) => import("./transactions/evm-local-signer").EvmLocalAccount;
136
+ getAccountXpub: () => string;
137
+ isSeedValid: (seedPhrase: string) => any;
138
+ createNewSeed: (wordCount?: number) => any;
139
+ getUTXOState: () => any;
140
+ importTrezorAccount(label?: string): Promise<IKeyringAccountState<any>>;
141
+ importLedgerAccount(label?: string): Promise<IKeyringAccountState<any>>;
142
+ getActiveUTXOAccountState: () => any;
143
+ getNetwork: () => any;
144
+ createEthAccount: (privateKey: string) => import("./transactions/evm-local-signer").EvmLocalAccount;
145
+ private fetchCurrentAccountData;
146
+ getAddress: (xpub: string, isChangeAddress: boolean, options?: {
147
+ forceIndex0?: boolean;
148
+ }) => Promise<string>;
149
+ getCurrentAddressPubkey: (xpub: string, isChangeAddress: boolean) => Promise<string>;
150
+ getCurrentAddressBip32Path: (xpub: string, isChangeAddress: boolean) => Promise<string>;
151
+ logout: () => void;
152
+ importAccount(privKey: string, label?: string, options?: {
153
+ utxoAddressType?: 'p2wpkh' | 'p2pkh' | 'p2tr';
154
+ }): Promise<IKeyringAccountState<any>>;
155
+ importWatchOnly(identifier: string, label?: string): Promise<IKeyringAccountState<any>>;
156
+ validateZprv(zprv: string, targetNetwork?: INetwork): {
157
+ isValid: boolean;
158
+ node: any;
159
+ network: {
160
+ bip32: {
161
+ public: number;
162
+ private: number;
163
+ };
164
+ messagePrefix: string;
165
+ bech32: string;
166
+ pubKeyHash: any;
167
+ scriptHash: any;
168
+ slip44: any;
169
+ wif: any;
170
+ };
171
+ message: string;
172
+ } | {
173
+ isValid: boolean;
174
+ message: any;
175
+ node?: undefined;
176
+ network?: undefined;
177
+ };
178
+ validateWif(wif: string, targetNetwork?: INetwork): {
179
+ isValid: boolean;
180
+ message?: undefined;
181
+ } | {
182
+ isValid: boolean;
183
+ message: any;
184
+ };
185
+ /**
186
+ * PRIVATE METHODS
187
+ */
188
+ private getDecryptedPrivateKey;
189
+ private capturePsbtSigningContext;
190
+ /** Fixed-path derivation for an authenticated software host; no persistence. */
191
+ protected deriveSoftwareEvmHdRuntimeAccount(input: EvmHdRuntimeAccountRequest, options: EvmHdRuntimeAccountOptions): Promise<EncryptedEvmHdRuntimeAccount>;
192
+ /** The software facade owns this public capability; no device fallback. */
193
+ protected signPreparedSoftwareEvmTransaction(input: PreparedSoftwareEvmSigningRequest, options: PreparedEvmSigningOptions): SignedPreparedEvmTransaction;
194
+ private getSigner;
195
+ private getReadOnlySigner;
196
+ private writeUtf8Diagnostic;
197
+ private validateAndHandleErrorByMessage;
198
+ private getAccountsState;
199
+ /**
200
+ *
201
+ * @param password
202
+ * @param salt
203
+ * @returns derived key: hex string
204
+ */
205
+ private encryptSHA512;
206
+ private hasWebCrypto;
207
+ private hexToBytes;
208
+ private bytesToHex;
209
+ private getEncIterations;
210
+ private pbkdf2WebCryptoHex;
211
+ private encryptSHA512Async;
212
+ private deriveLegacySessionKey;
213
+ private deriveStoredSessionKey;
214
+ private getSysActivePrivateKey;
215
+ private getInitialAccountData;
216
+ private _createTrezorAccount;
217
+ private _createLedgerAccount;
218
+ private getFormattedBackendAccount;
219
+ private setLatestIndexesFromXPubTokens;
220
+ private createUTXOAccountAtIndex;
221
+ private addNewAccountToSyscoinChain;
222
+ private addNewAccountToEth;
223
+ private getNextAccountId;
224
+ private getBasicWeb3AccountInfo;
225
+ private setDerivedWeb3Accounts;
226
+ private setSignerEVM;
227
+ private clearTemporaryLocalKeys;
228
+ private recreateSessionFromVault;
229
+ private _getPrivateKeyAccountInfos;
230
+ /**
231
+ * Common method to decrypt mnemonic from session
232
+ * Eliminates code duplication across multiple methods
233
+ */
234
+ private getDecryptedMnemonic;
235
+ /**
236
+ * Creates network RPC config from current active network without making RPC calls
237
+ * Common utility for all on-demand signer creation
238
+ */
239
+ private createNetworkRpcConfig;
240
+ /**
241
+ * Common signer creation logic - takes decrypted mnemonic/zprv and creates fresh signer
242
+ * OPTIMIZED: No RPC call needed - uses network config directly
243
+ */
244
+ private createFreshUTXOSigner;
245
+ /**
246
+ * Creates a fresh UTXO signer for HD accounts derived from the main seed
247
+ * OPTIMIZED: No RPC call needed - uses network config directly
248
+ */
249
+ private createOnDemandUTXOSigner;
250
+ private isZprv;
251
+ initializeSession: (seedPhrase: string, password: string) => Promise<void>;
252
+ createFirstAccount: (label?: string) => Promise<IKeyringAccountState>;
253
+ initializeWalletSecurely: (seedPhrase: string, password: string) => Promise<IKeyringAccountState>;
254
+ private getSessionPasswordString;
255
+ private getSessionMnemonicString;
256
+ private withSecureData;
257
+ private generateNetworkAwareLabel;
258
+ /**
259
+ * Clean up all resources
260
+ */
261
+ destroy(): Promise<void>;
262
+ }
263
+ export {};
@@ -1,229 +1,12 @@
1
- import { INetwork, INetworkType } from '@sidhujag/sysweb3-network';
2
1
  import { HardwareWalletManager } from './hardware-wallet-manager';
2
+ import { KeyringCore } from './keyring-core';
3
3
  import { LedgerKeyring } from './ledger';
4
- import { IDecryptPrivateRecordParams, IEncryptedPrivateRecord, IEncryptPrivateRecordParams } from './private-records';
5
- import { SyscoinHDSigner } from './signers';
6
4
  import { TrezorKeyring } from './trezor';
7
- import { IKeyringAccountState, ICreateSmartAccountParams, ISyscoinTransactions, KeyringAccountType, IEthereumTransactions, IKeyringManager } from './types';
8
- export interface ISysAccount {
9
- address: string;
10
- label?: string;
11
- xprv?: string;
12
- xpub: string;
13
- }
14
- /**
15
- * Secure Buffer implementation for sensitive data
16
- * Provides explicit memory clearing capability
17
- */
18
- declare class SecureBuffer {
19
- private buffer;
20
- private _isCleared;
21
- constructor(data: string | Buffer);
22
- get(): Buffer;
23
- toString(): string;
24
- clear(): void;
25
- isCleared(): boolean;
26
- }
27
- export declare class KeyringManager implements IKeyringManager {
28
- trezorSigner: TrezorKeyring;
29
- ledgerSigner: LedgerKeyring;
30
- initialTrezorAccountState: IKeyringAccountState;
31
- initialLedgerAccountState: IKeyringAccountState;
32
- utf8Error: boolean;
33
- ethereumTransaction: IEthereumTransactions;
34
- syscoinTransaction: ISyscoinTransactions;
35
- private storage;
36
- private getVaultState;
37
- setVaultStateGetter: (getter: () => any) => void;
38
- private getVault;
39
- private getActiveChain;
40
- private accountAddressExists;
41
- private sessionPassword;
42
- private sessionMnemonic;
43
- private privateRecordSessionRevision;
44
- /**
45
- * @param sharedHardwareWalletManager Optional shared HardwareWalletManager instance.
46
- * If not provided, the singleton instance will be used.
47
- * This allows multiple KeyringManagers to share the same
48
- * hardware wallet connections, preventing "device already open" errors.
49
- */
50
- constructor(sharedHardwareWalletManager?: HardwareWalletManager);
5
+ import type { IKeyringManager } from './types';
6
+ import type { LedgerHost } from './ledger/host-types';
7
+ export type { ISysAccount } from './keyring-core';
8
+ /** Existing browser entry. Native/software hosts must use the software entry. */
9
+ export declare class KeyringManager extends KeyringCore<LedgerKeyring, TrezorKeyring> implements IKeyringManager {
10
+ constructor(sharedHardwareWalletManager?: HardwareWalletManager, ledgerHost?: LedgerHost);
51
11
  static createInitialized(seed: string, password: string, vaultStateGetter: () => any): Promise<KeyringManager>;
52
- initialize(seed: string, password: string, network?: INetwork): Promise<IKeyringAccountState>;
53
- setStorage: (client: any) => any;
54
- validateAccountType: (account: IKeyringAccountState) => KeyringAccountType.HDAccount | KeyringAccountType.Imported;
55
- isUnlocked: () => boolean;
56
- lockWallet: () => Promise<void>;
57
- transferSessionTo: (targetKeyring: IKeyringManager) => void;
58
- receiveSessionOwnership: (sessionPassword: SecureBuffer, sessionMnemonic: SecureBuffer) => void;
59
- addNewAccount: (label?: string) => Promise<IKeyringAccountState>;
60
- createSmartAccount: ({ address, deriveAccount, label, metadata, }: ICreateSmartAccountParams) => Promise<IKeyringAccountState>;
61
- /**
62
- * Returns canLogin:false only when the first vault authentication fails.
63
- * Storage, platform and session restoration failures reject so callers do
64
- * not charge a failed password attempt for an operational error.
65
- */
66
- unlock(password: string): Promise<{
67
- canLogin: boolean;
68
- needsAccountCreation?: boolean;
69
- }>;
70
- getNewChangeAddress: () => Promise<string>;
71
- getChangeAddress: (id: number) => Promise<string>;
72
- getPubkey: (id: number, isChangeAddress: boolean) => Promise<string>;
73
- getBip32Path: (id: number, isChangeAddress: boolean) => Promise<string>;
74
- updateReceivingAddress: () => Promise<string>;
75
- getAccountById: (id: number, accountType: KeyringAccountType) => Omit<IKeyringAccountState, "xprv">;
76
- getPrivateKeyByAccountId: (id: number, accountType: KeyringAccountType, pwd: string) => Promise<string>;
77
- getActiveAccount: () => {
78
- activeAccount: Omit<IKeyringAccountState, "xprv">;
79
- activeAccountType: KeyringAccountType;
80
- };
81
- private isDescriptor;
82
- private isXpubLike;
83
- private isWatchOnlyAccount;
84
- getEncryptedXprv: (hd: SyscoinHDSigner) => string;
85
- getSeed: (pwd: string) => Promise<any>;
86
- deriveSLHDSASetupSecretForAccount: ({ accountIndex, }: {
87
- accountIndex: number;
88
- }) => Promise<{
89
- derivationLabel: string;
90
- setupSecretHex: string;
91
- }>;
92
- encryptSLHDSASessionState: (plainText: string) => string;
93
- decryptSLHDSASessionState: (cipherText: string) => string;
94
- private privateRecordSession;
95
- /** Stable local profile identifier; never an account address or a key. */
96
- getPrivateRecordProfileId(): Promise<string>;
97
- /** Encrypt caller-owned bytes; persistence and encrypted backup belong to the caller. */
98
- encryptPrivateRecord(params: IEncryptPrivateRecordParams): Promise<IEncryptedPrivateRecord>;
99
- decryptPrivateRecord(params: IDecryptPrivateRecordParams): Promise<Uint8Array>;
100
- setSignerNetwork: (network: INetwork) => Promise<{
101
- activeChain?: INetworkType;
102
- success: boolean;
103
- }>;
104
- forgetMainWallet: (pwd: string) => Promise<void>;
105
- importWeb3Account: (mnemonicOrPrivKey: string) => import("./transactions/evm-local-signer").EvmLocalAccount;
106
- getAccountXpub: () => string;
107
- isSeedValid: (seedPhrase: string) => any;
108
- createNewSeed: (wordCount?: number) => any;
109
- getUTXOState: () => any;
110
- importTrezorAccount(label?: string): Promise<IKeyringAccountState<any>>;
111
- importLedgerAccount(label?: string): Promise<IKeyringAccountState<any>>;
112
- getActiveUTXOAccountState: () => any;
113
- getNetwork: () => any;
114
- createEthAccount: (privateKey: string) => import("./transactions/evm-local-signer").EvmLocalAccount;
115
- private fetchCurrentAccountData;
116
- getAddress: (xpub: string, isChangeAddress: boolean, options?: {
117
- forceIndex0?: boolean;
118
- }) => Promise<string>;
119
- getCurrentAddressPubkey: (xpub: string, isChangeAddress: boolean) => Promise<string>;
120
- getCurrentAddressBip32Path: (xpub: string, isChangeAddress: boolean) => Promise<string>;
121
- logout: () => void;
122
- importAccount(privKey: string, label?: string, options?: {
123
- utxoAddressType?: 'p2wpkh' | 'p2pkh' | 'p2tr';
124
- }): Promise<IKeyringAccountState<any>>;
125
- importWatchOnly(identifier: string, label?: string): Promise<IKeyringAccountState<any>>;
126
- validateZprv(zprv: string, targetNetwork?: INetwork): {
127
- isValid: boolean;
128
- node: any;
129
- network: {
130
- bip32: {
131
- public: number;
132
- private: number;
133
- };
134
- messagePrefix: string;
135
- bech32: string;
136
- pubKeyHash: any;
137
- scriptHash: any;
138
- slip44: any;
139
- wif: any;
140
- };
141
- message: string;
142
- } | {
143
- isValid: boolean;
144
- message: any;
145
- node?: undefined;
146
- network?: undefined;
147
- };
148
- validateWif(wif: string, targetNetwork?: INetwork): {
149
- isValid: boolean;
150
- message?: undefined;
151
- } | {
152
- isValid: boolean;
153
- message: any;
154
- };
155
- /**
156
- * PRIVATE METHODS
157
- */
158
- private getDecryptedPrivateKey;
159
- private capturePsbtSigningContext;
160
- private getSigner;
161
- private getReadOnlySigner;
162
- private writeUtf8Diagnostic;
163
- private validateAndHandleErrorByMessage;
164
- private getAccountsState;
165
- /**
166
- *
167
- * @param password
168
- * @param salt
169
- * @returns derived key: hex string
170
- */
171
- private encryptSHA512;
172
- private hasWebCrypto;
173
- private hexToBytes;
174
- private bytesToHex;
175
- private getEncIterations;
176
- private pbkdf2WebCryptoHex;
177
- private encryptSHA512Async;
178
- private deriveLegacySessionKey;
179
- private deriveStoredSessionKey;
180
- private getSysActivePrivateKey;
181
- private getInitialAccountData;
182
- private _createTrezorAccount;
183
- private _createLedgerAccount;
184
- private getFormattedBackendAccount;
185
- private setLatestIndexesFromXPubTokens;
186
- private createUTXOAccountAtIndex;
187
- private addNewAccountToSyscoinChain;
188
- private addNewAccountToEth;
189
- private getNextAccountId;
190
- private getBasicWeb3AccountInfo;
191
- private setDerivedWeb3Accounts;
192
- private setSignerEVM;
193
- private clearTemporaryLocalKeys;
194
- private recreateSessionFromVault;
195
- private _getPrivateKeyAccountInfos;
196
- /**
197
- * Common method to decrypt mnemonic from session
198
- * Eliminates code duplication across multiple methods
199
- */
200
- private getDecryptedMnemonic;
201
- /**
202
- * Creates network RPC config from current active network without making RPC calls
203
- * Common utility for all on-demand signer creation
204
- */
205
- private createNetworkRpcConfig;
206
- /**
207
- * Common signer creation logic - takes decrypted mnemonic/zprv and creates fresh signer
208
- * OPTIMIZED: No RPC call needed - uses network config directly
209
- */
210
- private createFreshUTXOSigner;
211
- /**
212
- * Creates a fresh UTXO signer for HD accounts derived from the main seed
213
- * OPTIMIZED: No RPC call needed - uses network config directly
214
- */
215
- private createOnDemandUTXOSigner;
216
- private isZprv;
217
- initializeSession: (seedPhrase: string, password: string) => Promise<void>;
218
- createFirstAccount: (label?: string) => Promise<IKeyringAccountState>;
219
- initializeWalletSecurely: (seedPhrase: string, password: string) => Promise<IKeyringAccountState>;
220
- private getSessionPasswordString;
221
- private getSessionMnemonicString;
222
- private withSecureData;
223
- private generateNetworkAwareLabel;
224
- /**
225
- * Clean up all resources
226
- */
227
- destroy(): Promise<void>;
228
12
  }
229
- export {};
@@ -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;