@sidhujag/sysweb3-keyring 1.0.628 → 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.
- package/CHANGELOG.md +22 -0
- package/README.md +66 -0
- package/cjs/hardware-wallet-manager.js +302 -128
- package/cjs/hardware-wallet-manager.js.map +1 -1
- package/cjs/keyring-core.js +93 -0
- package/cjs/keyring-core.js.map +1 -1
- package/cjs/keyring-manager.js +9 -3
- package/cjs/keyring-manager.js.map +1 -1
- package/cjs/ledger/bitcoin_client/lib/appClient.js.map +1 -1
- package/cjs/ledger/host-types.js +10 -0
- package/cjs/ledger/host-types.js.map +1 -0
- package/cjs/ledger/index.js +243 -447
- package/cjs/ledger/index.js.map +1 -1
- package/cjs/ledger/prepare-psbt.js +177 -0
- package/cjs/ledger/prepare-psbt.js.map +1 -0
- package/cjs/software-hd-account.js +23 -0
- package/cjs/software-hd-account.js.map +1 -0
- package/cjs/software.js +16 -0
- package/cjs/software.js.map +1 -1
- package/cjs/transactions/ethereum.js +55 -10
- package/cjs/transactions/ethereum.js.map +1 -1
- package/cjs/transactions/hardware-psbt.js +36 -44
- package/cjs/transactions/hardware-psbt.js.map +1 -1
- package/cjs/transactions/prepared-evm.js +196 -0
- package/cjs/transactions/prepared-evm.js.map +1 -0
- package/cjs/trezor/connect.js +243 -0
- package/cjs/trezor/connect.js.map +1 -0
- package/cjs/trezor/index.js +96 -58
- package/cjs/trezor/index.js.map +1 -1
- package/cjs/trezor/witness.js +25 -0
- package/cjs/trezor/witness.js.map +1 -0
- package/cjs/utils/psbt-account-scope.js +5 -3
- package/cjs/utils/psbt-account-scope.js.map +1 -1
- package/esm/errorUtils.js +72 -0
- package/esm/errorUtils.js.map +1 -0
- package/esm/ethers-v6.js +207 -0
- package/esm/ethers-v6.js.map +1 -0
- package/esm/hardware-wallet-manager.js +643 -0
- package/esm/hardware-wallet-manager.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/appClient.js +279 -0
- package/esm/ledger/bitcoin_client/lib/appClient.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/bip32.js +49 -0
- package/esm/ledger/bitcoin_client/lib/bip32.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/buffertools.js +119 -0
- package/esm/ledger/bitcoin_client/lib/buffertools.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/clientCommands.js +269 -0
- package/esm/ledger/bitcoin_client/lib/clientCommands.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/merkelizedPsbt.js +50 -0
- package/esm/ledger/bitcoin_client/lib/merkelizedPsbt.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/merkle.js +111 -0
- package/esm/ledger/bitcoin_client/lib/merkle.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/merkleMap.js +42 -0
- package/esm/ledger/bitcoin_client/lib/merkleMap.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/policy.js +68 -0
- package/esm/ledger/bitcoin_client/lib/policy.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/psbtv2.js +645 -0
- package/esm/ledger/bitcoin_client/lib/psbtv2.js.map +1 -0
- package/esm/ledger/bitcoin_client/lib/varint.js +108 -0
- package/esm/ledger/bitcoin_client/lib/varint.js.map +1 -0
- package/esm/ledger/consts.js +4 -0
- package/esm/ledger/consts.js.map +1 -0
- package/esm/ledger/dmk-evm.js +258 -0
- package/esm/ledger/dmk-evm.js.map +1 -0
- package/esm/ledger/dmk-session.js +264 -0
- package/esm/ledger/dmk-session.js.map +1 -0
- package/esm/ledger/dmk-utxo.js +279 -0
- package/esm/ledger/dmk-utxo.js.map +1 -0
- package/esm/ledger/host-types.js +5 -0
- package/esm/ledger/host-types.js.map +1 -0
- package/esm/ledger/index.js +268 -0
- package/esm/ledger/index.js.map +1 -0
- package/esm/ledger/prepare-psbt.js +141 -0
- package/esm/ledger/prepare-psbt.js.map +1 -0
- package/esm/ledger/types.js +2 -0
- package/esm/ledger/types.js.map +1 -0
- package/esm/ledger-host.js +36 -0
- package/esm/ledger-host.js.map +1 -0
- package/esm/private-records.js +153 -0
- package/esm/private-records.js.map +1 -0
- package/esm/providers.js +588 -0
- package/esm/providers.js.map +1 -0
- package/esm/signers.js +28 -0
- package/esm/signers.js.map +1 -0
- package/esm/trezor/connect.js +206 -0
- package/esm/trezor/connect.js.map +1 -0
- package/esm/trezor/index.js +876 -0
- package/esm/trezor/index.js.map +1 -0
- package/esm/trezor/witness.js +21 -0
- package/esm/trezor/witness.js.map +1 -0
- package/esm/types.js +17 -0
- package/esm/types.js.map +1 -0
- package/esm/utils/derivation-paths.js +109 -0
- package/esm/utils/derivation-paths.js.map +1 -0
- package/esm/utils/psbt-account-scope.js +310 -0
- package/esm/utils/psbt-account-scope.js.map +1 -0
- package/package.json +21 -8
- package/types/hardware-wallet-manager.d.ts +12 -19
- package/types/keyring-core.d.ts +6 -0
- package/types/keyring-manager.d.ts +2 -1
- package/types/ledger/bitcoin_client/lib/appClient.d.ts +6 -3
- package/types/ledger/dmk-evm.d.ts +8 -0
- package/types/ledger/dmk-session.d.ts +60 -0
- package/types/ledger/dmk-utxo.d.ts +26 -0
- package/types/ledger/host-types.d.ts +131 -0
- package/types/ledger/index.d.ts +21 -58
- package/types/ledger/prepare-psbt.d.ts +3 -0
- package/types/ledger/types.d.ts +3 -0
- package/types/ledger-host.d.ts +7 -0
- package/types/software-hd-account.d.ts +16 -0
- package/types/software.d.ts +16 -0
- package/types/transactions/ethereum.d.ts +1 -1
- package/types/transactions/prepared-evm.d.ts +53 -0
- package/types/trezor/connect.d.ts +42 -0
- package/types/trezor/index.d.ts +22 -4
- package/types/trezor/witness.d.ts +3 -0
- 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
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
*/
|
package/types/keyring-core.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { SyscoinHDSigner } from './signers';
|
|
|
4
4
|
import { type ISyscoinHardwareSigners } from './transactions/syscoin-core';
|
|
5
5
|
import { IKeyringAccountState, ICreateSmartAccountParams, ISyscoinTransactions, KeyringAccountType, IEthereumTransactions } from './types';
|
|
6
6
|
import type { LedgerKeyring } from './ledger';
|
|
7
|
+
import type { EncryptedEvmHdRuntimeAccount, EvmHdRuntimeAccountOptions, EvmHdRuntimeAccountRequest } from './software-hd-account';
|
|
7
8
|
import type { VaultPersistence, VaultStoragePort } from './storage-core';
|
|
9
|
+
import type { PreparedEvmSigningOptions, PreparedSoftwareEvmSigningRequest, SignedPreparedEvmTransaction } from './transactions/prepared-evm';
|
|
8
10
|
import type { TrezorKeyring } from './trezor';
|
|
9
11
|
/** Explicit asynchronous host storage; no browser or global DI fallback. */
|
|
10
12
|
export interface KeyringStoragePort extends VaultStoragePort {
|
|
@@ -185,6 +187,10 @@ export declare class KeyringCore<TLedger extends KeyringLedgerSigner | undefined
|
|
|
185
187
|
*/
|
|
186
188
|
private getDecryptedPrivateKey;
|
|
187
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;
|
|
188
194
|
private getSigner;
|
|
189
195
|
private getReadOnlySigner;
|
|
190
196
|
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:
|
|
22
|
-
constructor(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
|
+
};
|
package/types/ledger/index.d.ts
CHANGED
|
@@ -1,62 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import { IEvmMethods, IUTXOMethods } from './types';
|
|
5
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
private
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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;
|
package/types/ledger/types.d.ts
CHANGED
|
@@ -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,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;
|
package/types/software.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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 { PreparedEvmSigningOptions, PreparedSoftwareEvmSigningRequest, SignedPreparedEvmTransaction } from './transactions/prepared-evm';
|
|
4
6
|
declare const softwareHostBrand: unique symbol;
|
|
5
7
|
/** Opaque handle minted by createSoftwareKeyringHost; no injectable persistence. */
|
|
6
8
|
export interface SoftwareKeyringHost {
|
|
@@ -10,6 +12,18 @@ export interface SoftwareKeyringHost {
|
|
|
10
12
|
export declare const createSoftwareKeyringHost: (storage: KeyringStoragePort) => SoftwareKeyringHost;
|
|
11
13
|
export declare class SoftwareKeyring extends KeyringCore<undefined, undefined> {
|
|
12
14
|
constructor(host: SoftwareKeyringHost);
|
|
15
|
+
/**
|
|
16
|
+
* Derive a fixed-path Ethereum HD runtime account without network or storage
|
|
17
|
+
* writes. The returned password-encrypted xprv is internal runtime state,
|
|
18
|
+
* never a public account/catalogue DTO. The host owns index allocation.
|
|
19
|
+
*/
|
|
20
|
+
deriveEvmHdRuntimeAccount(request: EvmHdRuntimeAccountRequest, options: EvmHdRuntimeAccountOptions): Promise<EncryptedEvmHdRuntimeAccount>;
|
|
21
|
+
/**
|
|
22
|
+
* Sign exactly the prepared envelope without RPC, fee/nonce discovery or
|
|
23
|
+
* broadcasting. The host must journal the result before submitting it.
|
|
24
|
+
* A later lock cannot revoke already returned signed bytes.
|
|
25
|
+
*/
|
|
26
|
+
signPreparedEvmTransaction(request: PreparedSoftwareEvmSigningRequest, options: PreparedEvmSigningOptions): SignedPreparedEvmTransaction;
|
|
13
27
|
/** Software authorities cannot rebind their backing store after creation. */
|
|
14
28
|
setStorage: (client: any) => never;
|
|
15
29
|
/** Sessions may move only through the core's same-authority transfer path. */
|
|
@@ -21,3 +35,5 @@ export { INetworkType } from '@sidhujag/sysweb3-network';
|
|
|
21
35
|
export type { INetwork } from '@sidhujag/sysweb3-network';
|
|
22
36
|
export type { KeyringStoragePort } from './keyring-core';
|
|
23
37
|
export type { IKeyringAccountState } from './types';
|
|
38
|
+
export type { PreparedEvmTransaction, PreparedEvmSigningOptions, PreparedSoftwareEvmSigningRequest, SignedPreparedEvmTransaction, } from './transactions/prepared-evm';
|
|
39
|
+
export type { EncryptedEvmHdRuntimeAccount, EvmHdRuntimeAccountOptions, EvmHdRuntimeAccountRequest, } from './software-hd-account';
|
|
@@ -43,7 +43,7 @@ export declare class EthereumTransactions<TLedger extends EthereumLedgerSigner |
|
|
|
43
43
|
get web3Provider(): CustomJsonRpcProvider;
|
|
44
44
|
private ensureProvidersInitialized;
|
|
45
45
|
private isUtxoNetwork;
|
|
46
|
-
signTypedData: (addr: string, typedData: TypedDataV1 | TypedMessage<any>, version: SignTypedDataVersion) => Promise<
|
|
46
|
+
signTypedData: (addr: string, typedData: TypedDataV1 | TypedMessage<any>, version: SignTypedDataVersion) => Promise<string>;
|
|
47
47
|
verifyUtxoAddress: (accountIndex: number, currency: string, slip44: number) => Promise<string | undefined>;
|
|
48
48
|
verifyTypedSignature: (data: TypedDataV1 | TypedMessage<any>, signature: string, version: SignTypedDataVersion) => string;
|
|
49
49
|
ethSign: (params: string[]) => Promise<string>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fully specified type-0/type-2 transaction. Quantities are canonical decimal
|
|
3
|
+
* integer strings, nonce is at most MAX_SAFE_INTEGER, and gasLimit is uint64.
|
|
4
|
+
* Addresses must be nonzero hex addresses; valid casing is normalized. Data is
|
|
5
|
+
* even-length 0x hex, at most 16 KiB. Contract creation/access lists are omitted.
|
|
6
|
+
*/
|
|
7
|
+
export type PreparedEvmTransaction = Readonly<{
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
chainId: string;
|
|
11
|
+
nonce: string;
|
|
12
|
+
value: string;
|
|
13
|
+
gasLimit: string;
|
|
14
|
+
data: string;
|
|
15
|
+
} & ({
|
|
16
|
+
type: 0;
|
|
17
|
+
gasPrice: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: 2;
|
|
20
|
+
maxFeePerGas: string;
|
|
21
|
+
maxPriorityFeePerGas: string;
|
|
22
|
+
})>;
|
|
23
|
+
export type PreparedSoftwareEvmSigningRequest = Readonly<{
|
|
24
|
+
account: Readonly<{
|
|
25
|
+
id: number;
|
|
26
|
+
type: 'HDAccount' | 'Imported';
|
|
27
|
+
expectedAddress: string;
|
|
28
|
+
}>;
|
|
29
|
+
network: Readonly<{
|
|
30
|
+
kind: 'ethereum';
|
|
31
|
+
chainId: string;
|
|
32
|
+
slip44: 60;
|
|
33
|
+
/** Exact configured endpoint binding; signing does not contact or authenticate it. */
|
|
34
|
+
url: string;
|
|
35
|
+
}>;
|
|
36
|
+
transaction: PreparedEvmTransaction;
|
|
37
|
+
}>;
|
|
38
|
+
export type PreparedEvmSigningOptions = Readonly<{
|
|
39
|
+
/** Host-owned consent/session/review expiry check. Must return undefined. */
|
|
40
|
+
assertCurrent(): void;
|
|
41
|
+
}>;
|
|
42
|
+
export type SignedPreparedEvmTransaction = Readonly<{
|
|
43
|
+
rawTransaction: string;
|
|
44
|
+
hash: string;
|
|
45
|
+
unsignedHash: string;
|
|
46
|
+
from: string;
|
|
47
|
+
/** Canonical signed fields, checked against the requested envelope. */
|
|
48
|
+
transaction: PreparedEvmTransaction;
|
|
49
|
+
}>;
|
|
50
|
+
export declare function snapshotPreparedEvmRequest(input: unknown): PreparedSoftwareEvmSigningRequest;
|
|
51
|
+
export declare function preparedEvmGuard(input: unknown): () => void;
|
|
52
|
+
/** Internal, network-free signing. The key never becomes part of the result. */
|
|
53
|
+
export declare function signPreparedEvmEnvelope(transaction: PreparedEvmTransaction, privateKey: string): SignedPreparedEvmTransaction;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ConnectDynamicSettings, TrezorConnectPublicAPI } from '@trezor/connect-webextension';
|
|
2
|
+
type Client = TrezorConnectPublicAPI<ConnectDynamicSettings>;
|
|
3
|
+
declare const methods: readonly ["getFeatures", "getAccountInfo", "ethereumGetAddress", "ethereumGetPublicKey", "getPublicKey", "getAddress", "signTransaction", "ethereumSignTransaction", "signMessage", "ethereumSignMessage", "ethereumSignTypedData", "verifyMessage", "ethereumVerifyMessage"];
|
|
4
|
+
type Method = (typeof methods)[number];
|
|
5
|
+
type Compatible<T> = T extends {
|
|
6
|
+
success: false;
|
|
7
|
+
} ? T & {
|
|
8
|
+
payload: {
|
|
9
|
+
error: string;
|
|
10
|
+
code?: string;
|
|
11
|
+
};
|
|
12
|
+
} : T;
|
|
13
|
+
type CompatibleCall<FunctionType> = FunctionType extends {
|
|
14
|
+
(...args: infer A): infer R;
|
|
15
|
+
(...args: infer B): infer S;
|
|
16
|
+
(...args: infer C): infer T;
|
|
17
|
+
} ? {
|
|
18
|
+
(...args: A): Promise<Compatible<Awaited<R>>>;
|
|
19
|
+
(...args: B): Promise<Compatible<Awaited<S>>>;
|
|
20
|
+
(...args: C): Promise<Compatible<Awaited<T>>>;
|
|
21
|
+
} : never;
|
|
22
|
+
type Calls = {
|
|
23
|
+
[Name in Method]: CompatibleCall<Client[Name]>;
|
|
24
|
+
};
|
|
25
|
+
type ConnectionEvent = {
|
|
26
|
+
type: 'disconnected';
|
|
27
|
+
} | {
|
|
28
|
+
type: 'model';
|
|
29
|
+
model: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const subscribeTrezorEvents: (listener: (event: ConnectionEvent) => void) => (() => void);
|
|
32
|
+
declare const TrezorConnect: Calls & {
|
|
33
|
+
init: Client['init'];
|
|
34
|
+
dispose: () => Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
export declare const trezorResponseError: (response: {
|
|
37
|
+
payload?: {
|
|
38
|
+
error?: string;
|
|
39
|
+
code?: string;
|
|
40
|
+
};
|
|
41
|
+
}, prefix?: string) => Error;
|
|
42
|
+
export default TrezorConnect;
|