Skip to main content
Version: Next

Class: LedgerSigner<Transport>

Signer for accounts using a Ledger Nano S+/X signature

Type parameters​

NameType
Transportextends Record<any, any> = any

Implements​

Constructors​

constructor​

• new LedgerSigner<Transport>(transport, accountID, eip2645application?): LedgerSigner<Transport>

constructor of the LedgerSigner class.

Type parameters​

NameType
Transportextends Record<any, any> = any

Parameters​

NameTypeDefault valueDescription
transportTransportundefined5 transports are available to handle USB, bluetooth, Node, Web, Mobile. See Guides for more details.
accountIDnumberundefinedID of Ledger Nano (can handle 2**31 accounts).
eip2645application?string'LedgerW'A wallet is defined by an ERC2645 derivation path (6 items). One item is the application. Default value is LedgerW.

Returns​

LedgerSigner<Transport>

Example

import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
const myNodeTransport = await TransportNodeHid.create();
const myLedgerSigner = new LedgerSigner(myNodeTransport, 0);

Defined in​

src/signer/ledgerSigner.ts:75

Properties​

transporter​

• Readonly transporter: Transport

Defined in​

src/signer/ledgerSigner.ts:44


_transporter​

• Private _transporter: any

Defined in​

src/signer/ledgerSigner.ts:47


accountID​

• Readonly accountID: number

Defined in​

src/signer/ledgerSigner.ts:49


eip2645applicationName​

• Readonly eip2645applicationName: string

Defined in​

src/signer/ledgerSigner.ts:51


pathBuffer​

• Readonly pathBuffer: Uint8Array

Defined in​

src/signer/ledgerSigner.ts:53


appVersion​

• Private appVersion: string

Defined in​

src/signer/ledgerSigner.ts:55


pubKey​

• Protected pubKey: string

Defined in​

src/signer/ledgerSigner.ts:57


fullPubKey​

• Protected fullPubKey: string

Defined in​

src/signer/ledgerSigner.ts:59

Methods​

getPubKey​

â–¸ getPubKey(): Promise<string>

provides the Starknet public key

Returns​

Promise<string>

an hex string : 64 characters are Point X coordinate.

Implementation of​

SignerInterface.getPubKey

Defined in​

src/signer/ledgerSigner.ts:93


getFullPubKey​

â–¸ getFullPubKey(): Promise<string>

provides the full public key (with parity prefix)

Returns​

Promise<string>

an hex string : 2 first characters are the parity, the 64 following characters are Point X coordinate. 64 last characters are Point Y coordinate.

Defined in​

src/signer/ledgerSigner.ts:102


getAppVersion​

â–¸ getAppVersion(): Promise<string>

Returns the version of the Starknet APP implemented in the Ledger.

Returns​

Promise<string>

version.

Example

const result = await myLedgerSigner.getAppVersion();
// result= "1.1.1"

Defined in​

src/signer/ledgerSigner.ts:116


signMessage​

â–¸ signMessage(typedDataToHash, accountAddress): Promise<Signature>

Signs a JSON object for off-chain usage with the private key and returns the signature. This adds a message prefix so it can't be interchanged with transactions

Parameters​

NameTypeDescription
typedDataToHashTypedDataJSON object to be signed
accountAddressstringHex string of the account's address

Returns​

Promise<Signature>

the signature of the message

Example

const mySigner = new Signer("0x123");
const myTypedData: TypedData = {
domain: {name: "Example DApp",
chainId: constants.StarknetChainId.SN_SEPOLIA,
version: "0.0.3"},
types: {StarkNetDomain: [
{ name: "name", type: "string" },
{ name: "chainId", type: "felt" },
{ name: "version", type: "string" }],
Message: [{ name: "message", type: "felt" }]},
primaryType: "Message", message: {message: "1234"}};
const result = await mySigner.signMessage(myTypedData,"0x5d08a4e9188429da4e993c9bf25aafe5cd491ee2b501505d4d059f0c938f82d");
// result = Signature {r: 684915484701699003335398790608214855489903651271362390249153620883122231253n,
// s: 1399150959912500412309102776989465580949387575375484933432871778355496929189n, recovery: 1}

Implementation of​

SignerInterface.signMessage

Defined in​

src/signer/ledgerSigner.ts:124


signTransaction​

â–¸ signTransaction(transactions, transactionsDetail): Promise<Signature>

Signs transactions with the private key and returns the signature

Parameters​

NameTypeDescription
transactionsCall[]array of Call objects
transactionsDetailInvocationsSignerDetailsInvocationsSignerDetails object

Returns​

Promise<Signature>

the signature of the transaction

Example

const mySigner = new Signer("0x123");
const calls: Call[] = [{
contractAddress: "0x1234567890123456789012345678901234567890",
entrypoint: "functionName",
calldata: [1, 2, 3]
}];
const transactionsDetail: InvocationsSignerDetails = {
walletAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
chainId: constants.StarknetChainId.SN_MAIN,
cairoVersion: "1",
maxFee: '0x1234567890abcdef',
version: "0x0", nonce: 1};
const result = await mySigner.signTransaction(calls, transactionsDetail);
// result = Signature {r: 304910226421970384958146916800275294114105560641204815169249090836676768876n,
// s: 1072798866000813654190523783606274062837012608648308896325315895472901074693n, recovery: 0}

Implementation of​

SignerInterface.signTransaction

Defined in​

src/signer/ledgerSigner.ts:129


signDeployAccountTransaction​

â–¸ signDeployAccountTransaction(details): Promise<Signature>

Signs a DEPLOY_ACCOUNT transaction with the private key and returns the signature

Parameters​

NameTypeDescription
detailsDeployAccountSignerDetailsto deploy an account contract

Returns​

Promise<Signature>

the signature of the transaction to deploy an account

Example

const mySigner = new Signer("0x123");
const myDeployAcc: DeployAccountSignerDetails = {
contractAddress: "0x65a822fbee1ae79e898688b5a4282dc79e0042cbed12f6169937fddb4c26641",
version: "0x2", chainId: constants.StarknetChainId.SN_SEPOLIA,
classHash: "0x5f3614e8671257aff9ac38e929c74d65b02d460ae966cd826c9f04a7fa8e0d4",
constructorCalldata: [1, 2],addressSalt: 1234,
nonce: 45, maxFee: 10 ** 15, tip: 0, paymasterData: [],accountDeploymentData: [],
nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
resourceBounds: stark.estimateFeeToBounds(constants.ZERO),
}
const result = await mySigner.signDeployAccountTransaction(myDeployAcc);
// result = Signature {r: 2871311234341436528393212130310036951068553852419934781736214693308640202748n,
// s: 1746271646048888422437132495446973163454853863041370993384284773665861377605n, recovery: 1}

Implementation of​

SignerInterface.signDeployAccountTransaction

Defined in​

src/signer/ledgerSigner.ts:162


signDeclareTransaction​

â–¸ signDeclareTransaction(details): Promise<Signature>

Signs a DECLARE transaction with the private key and returns the signature

Parameters​

NameTypeDescription
detailsDeclareSignerDetailsto declare a class

Returns​

Promise<Signature>

the signature of the transaction to declare a class

Example

const mySigner = new Signer("0x123");
const myDeclare: DeclareSignerDetails = {
version: "0x2", chainId: constants.StarknetChainId.SN_SEPOLIA,
senderAddress: "0x65a822fbee1ae79e898688b5a4282dc79e0042cbed12f6169937fddb4c26641",
classHash: "0x5f3614e8671257aff9ac38e929c74d65b02d460ae966cd826c9f04a7fa8e0d4",
nonce: 45, maxFee: 10 ** 15, tip: 0, paymasterData: [], accountDeploymentData: [],
nonceDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
feeDataAvailabilityMode: RPC.EDataAvailabilityMode.L1,
resourceBounds: stark.estimateFeeToBounds(constants.ZERO),
}
const result = await mySigner.signDeclareTransaction(myDeclare);
// result = Signature {r: 2432056944313955951711774394836075930010416436707488863728289188289211995670n,
// s: 3407649393310177489888603098175002856596469926897298636282244411990343146307n, recovery: 1}

Implementation of​

SignerInterface.signDeclareTransaction

Defined in​

src/signer/ledgerSigner.ts:194


signRaw​

â–¸ signRaw(msgHash): Promise<Signature>

Parameters​

NameType
msgHashstring

Returns​

Promise<Signature>

Defined in​

src/signer/ledgerSigner.ts:221


getPublicKeys​

â–¸ getPublicKeys(): Promise<void>

Returns​

Promise<void>

Defined in​

src/signer/ledgerSigner.ts:239